Class: QuickSearch::Adapters::MongoidAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/quick-search/adapters/mongoid_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(cls) ⇒ MongoidAdapter

Returns a new instance of MongoidAdapter.



4
5
6
# File 'lib/quick-search/adapters/mongoid_adapter.rb', line 4

def initialize(cls)
  @cls = cls
end

Instance Method Details

#default_quick_search_fieldsObject



12
13
14
# File 'lib/quick-search/adapters/mongoid_adapter.rb', line 12

def default_quick_search_fields
  @cls.fields.select { |_, f| f.type == String }.map(&:first)
end

#make_clauses_for_token(s, token, fields) ⇒ Object



8
9
10
# File 'lib/quick-search/adapters/mongoid_adapter.rb', line 8

def make_clauses_for_token(s, token, fields)
  s.and '$or' => fields.map { |f| { to_field_name(f) => /#{Regexp.escape token}/i } }
end