Method: SearchFlip::Filterable#where
- Defined in:
- lib/search_flip/filterable.rb
#where(hash) ⇒ SearchFlip::Criteria
Adds filters to your criteria for the supplied hash composed of field-to-filter mappings which specify terms, term or range filters, depending on the type of the respective hash value, namely array, range or scalar type like Fixnum, String, etc.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/search_flip/filterable.rb', line 54 def where(hash) hash.inject(fresh) do |memo, (key, value)| if value.is_a?(Array) memo.filter(terms: { key => value }) elsif value.is_a?(Range) memo.filter(range: { key => { gte: value.min, lte: value.max } }) elsif value.nil? memo.must_not(exists: { field: key }) else memo.filter(term: { key => value }) end end end |