Class: EsQueryBuilder::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/es-query-builder/parser.rb

Overview

Public: The class which has a responsibility for creatign a query.

Note that the term “query” has two different meanings in the terminology of Elasticsearch. One represents how to retrieve documents from Elasticsearch and it consists of query and filter, so that is to say the other is a part of previous one. In this file, “query” and “query hash” represents the former and the latter respectively:

"query" = "query hash" + "filter hash"

Instance Method Summary collapse

Constructor Details

#initialize(all_query_fields: '_all', hierarchy_fields: [], nested_fields: {}, child_fields: {}) ⇒ Parser

Public: Construct the parser object.

all_query_fields - A String or an Array of Strings for searching usual

query terms (default: '_all').

hierarchy_fields - An Array of Strings which treats the trailing slash

character as a hierarchy (default: []).

Returns nothing.



21
22
23
24
25
26
27
# File 'lib/es-query-builder/parser.rb', line 21

def initialize(all_query_fields: '_all', hierarchy_fields: [],
               nested_fields: {}, child_fields: {})
  @all_query_fields = all_query_fields
  @hierarchy_fields = hierarchy_fields
  @nested_fields = nested_fields
  @child_fields = child_fields
end

Instance Method Details

#parse(tokens) ⇒ Object

Public: Parse the given tokens and build a query hash.

tokens - An Array of Tokens.

Returns a Hash for Elasticsearch client or nil.



34
35
36
# File 'lib/es-query-builder/parser.rb', line 34

def parse(tokens)
  connect_queries(build_queries(tokens))
end