Module: LikeSearch::SearchMethods

Defined in:
lib/like_search.rb

Instance Method Summary collapse

Instance Method Details

#search(query) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/like_search.rb', line 23

def search(query)
  if query.present?
    where(format_search_sql, "%#{query}%")
  else
    scoped # TODO: test if only self works here
  end
end

#token_search(query) ⇒ Object



31
32
33
34
35
# File 'lib/like_search.rb', line 31

def token_search(query)
  query.to_s.split.inject(scoped) do |current_scope, term|
    term.size > 3 ? current_scope.search(term) : current_scope
  end
end