Module: Elastic::Dsl::BoolQueryBuilder

Included in:
BoolQueryContext, NestedQuery, Query
Defined in:
lib/elastic/dsl/bool_query_builder.rb

Instance Method Summary collapse

Instance Method Details

#boost(_amount = nil, field: nil, fixed: false, factor: 1, modifier: :none, missing: 1, &_block) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/elastic/dsl/bool_query_builder.rb', line 39

def boost(_amount = nil, field: nil, fixed: false, factor: 1, modifier: :none, missing: 1,
  &_block)
  raise ArgumentError, 'must provide at least a boost amount' if _amount.nil? && field.nil?

  node = Elastic::Nodes::FunctionScore.new
  node.boost_mode = :replace if fixed

  if !field.nil?
    node.add_field_function(field, factor: factor, modifier: modifier, missing: missing)
  elsif fixed
    node.add_weight_function(_amount)
  else
    node.boost = _amount
  end

  # TODO: add decay function support.

  with(node, &_block)
end

#coord_similarity(_enable) ⇒ Object



3
4
5
# File 'lib/elastic/dsl/bool_query_builder.rb', line 3

def coord_similarity(_enable)
  with_bool_query { |query| query.disable_coord = !_enable }
end

#must(*_queries) ⇒ Object



7
8
9
10
11
12
# File 'lib/elastic/dsl/bool_query_builder.rb', line 7

def must(*_queries)
  with_bool_query do |query|
    node = build_query_from_params(_queries)
    query.must node unless node.nil?
  end
end

#must_not(*_queries) ⇒ Object



14
15
16
17
18
19
# File 'lib/elastic/dsl/bool_query_builder.rb', line 14

def must_not(*_queries)
  with_bool_query do |query|
    node = build_query_from_params(_queries)
    query.must_not node unless node.nil?
  end
end

#should(*_queries) ⇒ Object



21
22
23
24
25
26
# File 'lib/elastic/dsl/bool_query_builder.rb', line 21

def should(*_queries)
  with_bool_query do |query|
    node = build_query_from_params(_queries)
    query.should node unless node.nil?
  end
end

#with(_modifier, &_block) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
# File 'lib/elastic/dsl/bool_query_builder.rb', line 28

def with(_modifier, &_block)
  raise ArgumentError, 'block missing' if _block.nil?
  raise ArgumentError, 'node is not a modifier' unless _modifier.respond_to? :clone_with_query

  with_bool_query do |query|
    ctx = BoolQueryContext.new index, query, _modifier
    ctx.instance_exec(&_block)
    ctx
  end
end