Class: PdfSearch::ElasticSearchQuery

Inherits:
Object
  • Object
show all
Includes:
Elasticsearch::DSL
Defined in:
lib/elastic_search_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_query_specification, search_index) ⇒ ElasticSearchQuery

Returns a new instance of ElasticSearchQuery.



8
9
10
11
# File 'lib/elastic_search_query.rb', line 8

def initialize(client_query_specification, search_index)
  @search_index =  search_index
  @client_query_specification = client_query_specification
end

Instance Attribute Details

#client_query_specificationObject (readonly)

Returns the value of attribute client_query_specification.



6
7
8
# File 'lib/elastic_search_query.rb', line 6

def client_query_specification
  @client_query_specification
end

#search_indexObject (readonly)

Returns the value of attribute search_index.



6
7
8
# File 'lib/elastic_search_query.rb', line 6

def search_index
  @search_index
end

Instance Method Details

#range_queriesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/elastic_search_query.rb', line 29

def range_queries
  return [] if search_index.search_input_fields_by_type.nil?
  search_index.search_input_fields_by_type[:interval].map do |name|
    {
      "range": {
        name => {
          gte: client_query_specification["search_#{name}_start"],
          lte: client_query_specification["search_#{name}_end"]
        }
      }
    }
  end
end

#to_hashObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/elastic_search_query.rb', line 13

def to_hash
  {
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "text": client_query_specification['search']
            }
          }
        ].concat(range_queries)
      }
    }
  }
end