Class: Stretchy::Queries::BoolQuery

Inherits:
Base
  • Object
show all
Defined in:
lib/stretchy/queries/bool_query.rb

Constant Summary

Constants included from Utils::Contract

Utils::Contract::ASSERTIONS, Utils::Contract::DECAY_FUNCTIONS, Utils::Contract::DISTANCE_FORMAT

Instance Method Summary collapse

Methods included from Utils::Contract

included, #require_one, #validate!

Constructor Details

#initialize(options = {}) ⇒ BoolQuery

Returns a new instance of BoolQuery.



7
8
9
10
11
# File 'lib/stretchy/queries/bool_query.rb', line 7

def initialize(options = {})
  @must       = Array(options[:must])
  @must_not   = Array(options[:must_not])
  @should     = Array(options[:should])
end

Instance Method Details

#to_searchObject



13
14
15
16
17
18
19
# File 'lib/stretchy/queries/bool_query.rb', line 13

def to_search
  json = {}
  json[:must]     = @must.map(&:to_search)      if @must.any?
  json[:must_not] = @must_not.map(&:to_search)  if @must_not.any?
  json[:should]   = @should.map(&:to_search)    if @should.any?
  { bool: json }
end