Class: Queries::DisMaxQueryBuilder

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

Overview

A query that generates the union of documents produced by its sub-queries, and that scores each document with the maximum score for that document as produced by any sub-query, plus a tie breaking increment for any additional matching sub-queries.

Instance Method Summary collapse

Methods inherited from QueryBuilder

#boost

Methods included from AttributesReader

#attributes

Methods included from AbstractQueryBuilder

#do_equals?, #name

Constructor Details

#initializeDisMaxQueryBuilder

Returns a new instance of DisMaxQueryBuilder.



15
16
17
18
# File 'lib/queries/dis_max_query_builder.rb', line 15

def initialize
  @queries = []
  @tie_breaker = DEFAULT_TIE_BREAKER
end

Instance Method Details

#add(query) ⇒ DisMaxQueryBuilder

add a sub-query to this disjunction

Returns:



63
64
65
66
67
68
# File 'lib/queries/dis_max_query_builder.rb', line 63

def add(query)
  raise 'Query for Dismax is nil' if query.nil?

  @queries.append(query)
  self
end

#inner_queries_exprObject

an immutable list copy of the current sub-queries of this disjunction



31
32
33
# File 'lib/queries/dis_max_query_builder.rb', line 31

def inner_queries_expr
  @queries
end

#queryObject



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

def query
  query = {}
  dm_query = common_query
  dm_query[:queries] = @queries.map(&:query) if @queries.present?
  dm_query[:tie_breaker] = @tie_breaker
  query[name.intern] = dm_query
  query
end

#tie_breaker(value) ⇒ DisMaxQueryBuilder

adds the tie_breaker value

Returns:



52
53
54
55
56
57
# File 'lib/queries/dis_max_query_builder.rb', line 52

def tie_breaker(value)
  raise 'Tie Breaker value is nil' if value.nil?

  @tie_breaker = value
  self
end