Class: Queries::TermsQueryBuilder
- Inherits:
-
QueryBuilder
- Object
- QueryBuilder
- Queries::TermsQueryBuilder
- Defined in:
- lib/queries/terms_query_builder.rb
Constant Summary collapse
- NAME =
"terms"
Instance Method Summary collapse
-
#field_name_expr ⇒ Object
FIELD NAME ########## returns field_name.
-
#initialize(field_name:, values: []) ⇒ TermsQueryBuilder
constructor
@params: field_name: name of the field in the document which is being queried values: values which are matched to the data in that field can be: Data Set: Directly matched to the data in the given field.
- #query ⇒ Object
-
#values_expr ⇒ Object
FIELD VALUE ########## returns value.
Methods inherited from QueryBuilder
Methods included from AttributesReader
Methods included from AbstractQueryBuilder
Constructor Details
#initialize(field_name:, values: []) ⇒ TermsQueryBuilder
@params:
field_name: name of the field in the document which is being queried
values: values which are matched to the data in that field can be:
Data Set:
Directly matched to the data in the given field.
Terms Lookup:
Terms lookup fetches the field values of an existing document.
Elasticsearch then uses those values as search terms. This can be helpful when searching for a large set of terms.
Because terms lookup fetches values from a document, the _source mapping field must be enabled to use terms lookup.
The _source field is enabled by default.
23 24 25 26 27 28 29 30 |
# File 'lib/queries/terms_query_builder.rb', line 23 def initialize field_name:, values: [] @field_name = field_name if values.is_a?(Misc::TermsLookup) @terms_lookup = values else @values = values.is_a?(Array) ? values : values.split(',') end end |
Instance Method Details
#field_name_expr ⇒ Object
FIELD NAME ########## returns field_name
43 44 45 |
# File 'lib/queries/terms_query_builder.rb', line 43 def field_name_expr return @field_name end |
#query ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/queries/terms_query_builder.rb', line 32 def query query = {} terms_query = self.common_query terms_query[@field_name.intern] = @values terms_query[@field_name.intern] = @terms_lookup.settings if @terms_lookup.present? query[name.intern] = terms_query return query end |
#values_expr ⇒ Object
FIELD VALUE ########## returns value
49 50 51 |
# File 'lib/queries/terms_query_builder.rb', line 49 def values_expr return @terms_lookup || @values end |