class ElasticsearchQueryParser::Grammar::Presenters::Query
Attributes
nested_query[R]
operator[R]
terms[R]
Public Class Methods
new(terms, operator, nested_query)
click to toggle source
# File lib/elasticsearch_query_parser/grammar/presenters/query.rb, line 8 def initialize(terms, operator, nested_query) @terms = terms @operator = operator @nested_query = nested_query end
Public Instance Methods
to_elasticsearch(include_bool_header = true)
click to toggle source
If its `must_not` operator - just add `must_not` to root node and continue analyze nested queries Otherwise for nested query add new nested nodes
# File lib/elasticsearch_query_parser/grammar/presenters/query.rb, line 16 def to_elasticsearch(include_bool_header = true) query = if operator.to_elasticsearch == :must_not result = nested_query[0].to_elasticsearch(false) result.merge(must_not: result.fetch(:must_not, []) + match_query(terms)) else { operator.to_elasticsearch => match_query(terms + nested_query) } end include_bool_header ? { bool: query } : query end
Private Instance Methods
match_query(sentence)
click to toggle source
if is a term then build match query, otherwise (nested query) - just add to query as is
# File lib/elasticsearch_query_parser/grammar/presenters/query.rb, line 29 def match_query(sentence) sentence.map do |expression| if expression.is_a?(Term) { match: { search_field_name => expression.to_elasticsearch } } else expression.to_elasticsearch end end end
search_field_name()
click to toggle source
# File lib/elasticsearch_query_parser/grammar/presenters/query.rb, line 39 def search_field_name ::ElasticsearchQueryParser.configuration.elastic_field_name end