Class: Tire::Search::BooleanQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/tire/search/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ BooleanQuery

TODO: Try to get rid of multiple ‘should`, `must`, etc invocations, and wrap queries directly:

boolean do
  should do
    string 'foo'
    string 'bar'
  end
end

Inherit from Query, implement ‘encode` method there, and overload it here, so it puts queries in an Array instead of hash.



111
112
113
114
115
# File 'lib/tire/search/query.rb', line 111

def initialize(options={}, &block)
  @options = options
  @value   = {}
  block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
end

Instance Method Details

#must(&block) ⇒ Object



117
118
119
120
# File 'lib/tire/search/query.rb', line 117

def must(&block)
  (@value[:must] ||= []) << Query.new(&block).to_hash
  @value
end

#must_not(&block) ⇒ Object



122
123
124
125
# File 'lib/tire/search/query.rb', line 122

def must_not(&block)
  (@value[:must_not] ||= []) << Query.new(&block).to_hash
  @value
end

#should(&block) ⇒ Object



127
128
129
130
# File 'lib/tire/search/query.rb', line 127

def should(&block)
  (@value[:should] ||= []) << Query.new(&block).to_hash
  @value
end

#to_hashObject



132
133
134
# File 'lib/tire/search/query.rb', line 132

def to_hash
  @value.update(@options)
end