class Tire::Search::Query

Public Class Methods

new(&block) click to toggle source
# File lib/tire/search/query.rb, line 5
def initialize(&block)
  @value = {}
  block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
end

Public Instance Methods

all() click to toggle source
# File lib/tire/search/query.rb, line 58
def all
  @value = { :match_all => {} }
  @value
end
boolean(options={}, &block) click to toggle source
# File lib/tire/search/query.rb, line 44
def boolean(options={}, &block)
  @boolean ||= BooleanQuery.new(options)
  block.arity < 1 ? @boolean.instance_eval(&block) : block.call(@boolean) if block_given?
  @value[:bool] = @boolean.to_hash
  @value
end
custom_score(options={}, &block) click to toggle source
# File lib/tire/search/query.rb, line 37
def custom_score(options={}, &block)
  @custom_score ||= Query.new(&block)
  @value[:custom_score] = options
  @value[:custom_score].update({:query => @custom_score.to_hash})
  @value
end
filtered(&block) click to toggle source
# File lib/tire/search/query.rb, line 51
def filtered(&block)
  @filtered = FilteredQuery.new
  block.arity < 1 ? @filtered.instance_eval(&block) : block.call(@filtered) if block_given?
  @value[:filtered] = @filtered.to_hash
  @value
end
ids(values, type) click to toggle source
# File lib/tire/search/query.rb, line 63
def ids(values, type)
  @value = { :ids => { :values => values, :type => type }  }
end
range(field, value) click to toggle source
# File lib/tire/search/query.rb, line 20
def range(field, value)
  @value = { :range => { field => value } }
end
string(value, options={}) click to toggle source
# File lib/tire/search/query.rb, line 30
def string(value, options={})
  @value = { :query_string => { :query => value } }
  @value[:query_string].update(options)
  # TODO: https://github.com/elasticsearch/elasticsearch/wiki/Query-String-Query
  @value
end
term(field, value) click to toggle source
# File lib/tire/search/query.rb, line 10
def term(field, value)
  @value = { :term => { field => value } }
end
terms(field, value, options={}) click to toggle source
# File lib/tire/search/query.rb, line 14
def terms(field, value, options={})
  @value = { :terms => { field => value } }
  @value[:terms].update( { :minimum_match => options[:minimum_match] } ) if options[:minimum_match]
  @value
end
text(field, value, options={}) click to toggle source
# File lib/tire/search/query.rb, line 24
def text(field, value, options={})
  query_options = { :query => value }.update(options)
  @value = { :text => { field => query_options } }
  @value
end
to_hash() click to toggle source
# File lib/tire/search/query.rb, line 67
def to_hash
  @value
end
to_json() click to toggle source
# File lib/tire/search/query.rb, line 71
def to_json
  to_hash.to_json
end