Class: Tire::Search::FilteredQuery

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ FilteredQuery

Returns a new instance of FilteredQuery.



159
160
161
162
# File 'lib/tire/search/query.rb', line 159

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

Instance Method Details

#filter(type, *options) ⇒ Object



169
170
171
172
173
174
# File 'lib/tire/search/query.rb', line 169

def filter(type, *options)
  @value[:filter] ||= {}
  @value[:filter][:and] ||= []
  @value[:filter][:and] << Filter.new(type, *options).to_hash
  @value
end

#query(options = {}, &block) ⇒ Object



164
165
166
167
# File 'lib/tire/search/query.rb', line 164

def query(options={}, &block)
  @value[:query] = Query.new(&block).to_hash
  @value
end

#to_hashObject



176
177
178
# File 'lib/tire/search/query.rb', line 176

def to_hash
  @value
end

#to_json(options = {}) ⇒ Object



180
181
182
# File 'lib/tire/search/query.rb', line 180

def to_json(options={})
  to_hash.to_json
end