Class: Estella::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/estella/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Query

Returns a new instance of Query.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/estella/query.rb', line 7

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

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/estella/query.rb', line 5

def params
  @params
end

#queryObject

Constructs a search query for ES



4
5
6
# File 'lib/estella/query.rb', line 4

def query
  @query
end

Instance Method Details

#exclude(filter) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/estella/query.rb', line 28

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_factorsObject



46
47
48
# File 'lib/estella/query.rb', line 46

def field_factors
  Estella::Analysis::DEFAULT_FIELD_FACTORS
end

#must(filter) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/estella/query.rb', line 20

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_definitionObject



36
37
38
39
40
41
42
43
44
# File 'lib/estella/query.rb', line 36

def term_query_definition
  {
    multi_match: {
      type: 'most_fields',
      fields: term_search_fields,
      query: params[:term]
    }
  }
end