Class: Estella::Query
- Inherits:
-
Object
- Object
- Estella::Query
- Defined in:
- lib/estella/query.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#query ⇒ Object
Constructs a search query for ES.
Instance Method Summary collapse
- #exclude(filter) ⇒ Object
- #field_factors ⇒ Object
-
#initialize(params) ⇒ Query
constructor
A new instance of Query.
- #must(filter) ⇒ Object
- #term_query_definition ⇒ Object
Constructor Details
#initialize(params) ⇒ Query
Returns a new instance of Query.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/estella/query.rb', line 9 def initialize(params) @params = params @query = { _source: false, query: { bool: { must: [{ match_all: {} }], must_not: [], filter: [] } }, aggregations: {} } add_query add_filters add_excludes add_pagination end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/estella/query.rb', line 7 def params @params end |
#query ⇒ Object
Constructs a search query for ES
6 7 8 |
# File 'lib/estella/query.rb', line 6 def query @query end |
Instance Method Details
#exclude(filter) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/estella/query.rb', line 30 def exclude(filter) if query[:query][:function_score] query[:query][:function_score][:query][:bool][:must_not] << filter else query[:query][:bool][:must_not] << filter end end |
#field_factors ⇒ Object
48 49 50 |
# File 'lib/estella/query.rb', line 48 def field_factors Estella::Analysis::DEFAULT_FIELD_FACTORS end |
#must(filter) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/estella/query.rb', line 22 def must(filter) if query[:query][:function_score] query[:query][:function_score][:query][:bool][:filter] << filter else query[:query][:bool][:filter] << filter end end |
#term_query_definition ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/estella/query.rb', line 38 def term_query_definition { multi_match: { type: 'most_fields', fields: term_search_fields, query: params[:term] } } end |