Class: Daedal::Queries::BoolQuery

Inherits:
BaseQuery
  • Object
show all
Defined in:
lib/daedal/queries/bool_query.rb

Instance Method Summary collapse

Methods inherited from BaseQuery

#to_json

Instance Method Details

#add_must_not_query(q) ⇒ Object



34
35
36
37
# File 'lib/daedal/queries/bool_query.rb', line 34

def add_must_not_query(q)
  verify_query(q)
  must_not << q
end

#add_must_query(q) ⇒ Object



29
30
31
32
# File 'lib/daedal/queries/bool_query.rb', line 29

def add_must_query(q)
  verify_query(q)
  must << q
end

#add_should_query(q) ⇒ Object



24
25
26
27
# File 'lib/daedal/queries/bool_query.rb', line 24

def add_should_query(q)
  verify_query(q)
  should << q
end

#to_hashObject



39
40
41
42
43
44
45
# File 'lib/daedal/queries/bool_query.rb', line 39

def to_hash
  result = {bool: {should: should.map {|q| q.to_hash}, must: must.map {|q| q.to_hash}, must_not: must_not.map {|q| q.to_hash}}}
  options = {minimum_should_match: minimum_should_match, boost: boost}
  result[:bool].merge!(options.select { |k,v| !v.nil? })
  
  result
end

#verify_query(q) ⇒ Object



18
19
20
21
22
# File 'lib/daedal/queries/bool_query.rb', line 18

def verify_query(q)
  unless q.is_a? Daedal::Queries::BaseQuery
    raise "Must give a valid query"
  end
end