Module: SearchAble::ClassMethods

Defined in:
lib/app/models/concerns/search_able.rb

Overview

Public: Add to class methods a way to search for records with matching search text.

Examples

Model.matching_search_text('some text')
# => <Mongoid::critera>

Instance Method Summary collapse

Instance Method Details

#matching_search_text(search_text = nil) ⇒ Object



33
34
35
# File 'lib/app/models/concerns/search_able.rb', line 33

def matching_search_text(search_text = nil)
  (search_text.blank? ? all : where(search_text: /#{search_text.downcase}/)).order([:sort_text, 1])
end

#sort_orderObject



37
38
39
# File 'lib/app/models/concerns/search_able.rb', line 37

def sort_order
  new.sort_fields.collect { |field| [field, 1] }
end