Class: Elasticband::Filter
- Inherits:
-
Object
- Object
- Elasticband::Filter
- Defined in:
- lib/elasticband/filter.rb,
lib/elasticband/filter/and.rb,
lib/elasticband/filter/not.rb,
lib/elasticband/filter/near.rb,
lib/elasticband/filter/term.rb,
lib/elasticband/filter/query.rb,
lib/elasticband/filter/range.rb,
lib/elasticband/filter/terms.rb,
lib/elasticband/filter/exists.rb,
lib/elasticband/filter/script.rb
Defined Under Namespace
Classes: And, Exists, Near, Not, Query, Range, Script, Term, Terms
Constant Summary collapse
- PARSE_FILTERS =
%i(only except exists includes range near).freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.parse(options = {}) ⇒ Object
Parses filter options to a Elasticsearch syntax.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Filter
constructor
A new instance of Filter.
- #parse ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Filter
Returns a new instance of Filter.
56 57 58 |
# File 'lib/elasticband/filter.rb', line 56 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/elasticband/filter.rb', line 15 def @options end |
Class Method Details
.parse(options = {}) ⇒ Object
Parses filter options to a Elasticsearch syntax
#### Options
-
‘only:` Filter the search results where the condition is `true`
-
‘except`: Filter the search results where the condition is `false`.
-
‘includes:` Filter the search results with a `Match` query.
-
‘range:` Filter the search results where the condition is on the given range.
-
‘near:` Filter the search results where the results are near a geo point.
-
‘script:` Filter the search results where the results match the script.
#### Examples “‘ Filter.parse(only: { status: :published })
> { term: { status: :published } }
Filter.parse(exists: :status)
> { exists: { field: :status } }
Filter.parse(except: { company: { id: 1 } })
> { not: { term: { status: :published } } }
Filter.parse(includes: [‘company’, on: :description])
> { query: { match: { description: ‘company’ } } }
Filter.parse(range: { companies_count: { gt: 1, gteq: 1, lt: 1, lteq: 1 } })
> { range: { companies_count: { gt: 1, gte: 1, lt: 1, lte: 1 } } }
Filter.parse(near: { latitude: 12, longitude: 34, distance: ‘5km’, type: :arc })
> { geo_distance: { location: { lat: 12, lon: 34 } }, distance: ‘5km’, distance_type: :arc }
Filter.parse(script: [‘(param1 + param2) > 0’, param1: 1, param2: 1])
> { script: { script: ‘(param1 + param2) > 0’, params: { param1: 1, param2: 1 } } }
“‘
52 53 54 |
# File 'lib/elasticband/filter.rb', line 52 def self.parse( = {}) new().parse end |
Instance Method Details
#parse ⇒ Object
60 61 62 63 64 |
# File 'lib/elasticband/filter.rb', line 60 def parse return {} if .blank? join_filters(filters).to_h end |
#to_h ⇒ Object
66 67 68 |
# File 'lib/elasticband/filter.rb', line 66 def to_h { match_all: {} } end |