Class: Queries::NestedQueryBuilder

Inherits:
QueryBuilder show all
Defined in:
lib/queries/nested_query_builder.rb

Constant Summary collapse

NAME =
"nested"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from QueryBuilder

#boost

Methods included from AttributesReader

#attributes

Methods included from AbstractQueryBuilder

#do_equals?, #name

Constructor Details

#initialize(path:, inner_query:, score_mode: nil, type: :query) ⇒ NestedQueryBuilder

@params:

  path: The query path points to the nested object path.
  score_mode: The score_mode allows to set how inner children matching affects scoring of parent.
              It defaults to avg, but can be sum, min, max and none.
  inner_query: query includes the query that will run on the nested docs matching the direct path, and joining with the root parent docs

Any fields referenced inside the query must use the complete path (fully qualified)


22
23
24
25
26
27
# File 'lib/queries/nested_query_builder.rb', line 22

def initialize path:, inner_query:, score_mode: nil, type: :query
  @path = path
  @inner_query = inner_query
  @score_mode = score_mode.score_mode if score_mode.present?
  @type = type
end

Instance Attribute Details

#inner_queryObject (readonly)

Returns the value of attribute inner_query.



11
12
13
# File 'lib/queries/nested_query_builder.rb', line 11

def inner_query
  @inner_query
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/queries/nested_query_builder.rb', line 11

def path
  @path
end

#score_modeObject (readonly)

Returns the value of attribute score_mode.



11
12
13
# File 'lib/queries/nested_query_builder.rb', line 11

def score_mode
  @score_mode
end

Instance Method Details

#inner_query_exprObject

returns inner_query



45
46
47
# File 'lib/queries/nested_query_builder.rb', line 45

def inner_query_expr
  return @inner_query
end

#path_exprObject

returns path



40
41
42
# File 'lib/queries/nested_query_builder.rb', line 40

def path_expr
  return @path
end

#queryObject



29
30
31
32
33
34
35
36
37
# File 'lib/queries/nested_query_builder.rb', line 29

def query
  query = {}
  nested_query = self.common_query
  nested_query[:path] = @path if @path.present?
  nested_query[@type] = @inner_query.query if @inner_query.present?
  nested_query[:score_mode] = @score_mode if @score_mode.present?
  query[name.intern] = nested_query
  return query
end

#score_mode_exprObject

returns score_mode



50
51
52
# File 'lib/queries/nested_query_builder.rb', line 50

def score_mode_expr
  return @score_mode
end