Class: Queries::DisMaxQueryBuilder
- Inherits:
-
QueryBuilder
- Object
- QueryBuilder
- Queries::DisMaxQueryBuilder
- 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
-
#add(query) ⇒ DisMaxQueryBuilder
add a sub-query to this disjunction.
-
#initialize ⇒ DisMaxQueryBuilder
constructor
A new instance of DisMaxQueryBuilder.
-
#inner_queries_expr ⇒ Object
an immutable list copy of the current sub-queries of this disjunction.
- #query ⇒ Object
-
#tie_breaker(value) ⇒ DisMaxQueryBuilder
adds the tie_breaker value.
Methods inherited from QueryBuilder
Methods included from AttributesReader
Methods included from AbstractQueryBuilder
Constructor Details
#initialize ⇒ DisMaxQueryBuilder
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
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_expr ⇒ Object
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 |
#query ⇒ Object
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
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 |