Class: Slingshot::Search::Query

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Query

Returns a new instance of Query.



5
6
7
# File 'lib/slingshot/search/query.rb', line 5

def initialize(&block)
  self.instance_eval(&block) if block_given?
end

Instance Method Details

#allObject



26
27
28
29
# File 'lib/slingshot/search/query.rb', line 26

def all
  @value = { :match_all => {} }
  @value
end

#ids(values, type) ⇒ Object



31
32
33
# File 'lib/slingshot/search/query.rb', line 31

def ids(values, type)
  @value = { :ids => { :values => values, :type => type }  }
end

#string(value, options = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/slingshot/search/query.rb', line 19

def string(value, options={})
  @value = { :query_string => { :query => value } }
  @value[:query_string].update( { :default_field => options[:default_field] } ) if options[:default_field]
  # TODO: https://github.com/elasticsearch/elasticsearch/wiki/Query-String-Query
  @value
end

#term(field, value) ⇒ Object



9
10
11
# File 'lib/slingshot/search/query.rb', line 9

def term(field, value)
  @value = { :term => { field => value } }
end

#terms(field, value, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/slingshot/search/query.rb', line 13

def terms(field, value, options={})
  @value = { :terms => { field => value } }
  @value[:terms].update( { :minimum_match => options[:minimum_match] } ) if options[:minimum_match]
  @value
end

#to_jsonObject



35
36
37
# File 'lib/slingshot/search/query.rb', line 35

def to_json
  @value.to_json
end