module Elastic::Dsl::BoolQueryBuilder

Public Instance Methods

boost(_amount = nil, field: nil, fixed: false, factor: 1, modifier: :none, missing: 1, &_block) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

build_query_from_params(_params) click to toggle source
# File lib/elastic/dsl/bool_query_builder.rb, line 61
def build_query_from_params(_params)
  Elastic::Commands::BuildQueryFromParams.for(index: index, params: _params)
end