Class: Tire::Search::Query
- Inherits:
-
Object
- Object
- Tire::Search::Query
- Defined in:
- lib/tire/search/query.rb,
lib/tire/search/queries/match.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
- #boolean(options = {}, &block) ⇒ Object
- #boosting(options = {}, &block) ⇒ Object
- #custom_score(options = {}, &block) ⇒ Object
- #dis_max(options = {}, &block) ⇒ Object
- #filtered(&block) ⇒ Object
- #fuzzy(field, value, options = {}) ⇒ Object
- #ids(values, type) ⇒ Object
-
#initialize(&block) ⇒ Query
constructor
A new instance of Query.
- #match(field, value, options = {}) ⇒ Object
- #nested(options = {}, &block) ⇒ Object
- #prefix(field, value, options = {}) ⇒ Object
- #range(field, value) ⇒ Object
- #string(value, options = {}) ⇒ Object
- #term(field, value, options = {}) ⇒ Object
- #terms(field, value, options = {}) ⇒ Object
- #text(field, value, options = {}) ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Query
Returns a new instance of Query.
7 8 9 10 |
# File 'lib/tire/search/query.rb', line 7 def initialize(&block) @value = {} block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given? end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/tire/search/query.rb', line 5 def value @value end |
Instance Method Details
#all(options = {}) ⇒ Object
92 93 94 95 |
# File 'lib/tire/search/query.rb', line 92 def all( = {}) @value = { :match_all => } @value end |
#boolean(options = {}, &block) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/tire/search/query.rb', line 64 def boolean(={}, &block) @boolean ||= BooleanQuery.new() block.arity < 1 ? @boolean.instance_eval(&block) : block.call(@boolean) if block_given? @value[:bool] = @boolean.to_hash @value end |
#boosting(options = {}, &block) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/tire/search/query.rb', line 101 def boosting(={}, &block) @boosting ||= BoostingQuery.new() block.arity < 1 ? @boosting.instance_eval(&block) : block.call(@boosting) if block_given? @value[:boosting] = @boosting.to_hash @value end |
#custom_score(options = {}, &block) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/tire/search/query.rb', line 52 def custom_score(={}, &block) @custom_score ||= Query.new(&block) @value[:custom_score] = @value[:custom_score].update({:query => @custom_score.to_hash}) @value end |
#dis_max(options = {}, &block) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/tire/search/query.rb', line 78 def dis_max(={}, &block) @dis_max ||= DisMaxQuery.new() block.arity < 1 ? @dis_max.instance_eval(&block) : block.call(@dis_max) if block_given? @value[:dis_max] = @dis_max.to_hash @value end |
#filtered(&block) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/tire/search/query.rb', line 71 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 |
#fuzzy(field, value, options = {}) ⇒ Object
59 60 61 62 |
# File 'lib/tire/search/query.rb', line 59 def fuzzy(field, value, ={}) query = { field => { :term => value }.update() } @value = { :fuzzy => query } end |
#ids(values, type) ⇒ Object
97 98 99 |
# File 'lib/tire/search/query.rb', line 97 def ids(values, type) @value = { :ids => { :values => values, :type => type } } end |
#match(field, value, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/tire/search/queries/match.rb', line 5 def match(field, value, ={}) if @value.empty? @value = MatchQuery.new(field, value, ).to_hash else MatchQuery.add(self, field, value, ) end @value end |
#nested(options = {}, &block) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/tire/search/query.rb', line 85 def nested(={}, &block) @nested = NestedQuery.new() block.arity < 1 ? @nested.instance_eval(&block) : block.call(@nested) if block_given? @value[:nested] = @nested.to_hash @value end |
#prefix(field, value, options = {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/tire/search/query.rb', line 44 def prefix(field, value, ={}) if [:boost] @value = { :prefix => { field => { :prefix => value, :boost => [:boost] } } } else @value = { :prefix => { field => value } } end end |
#range(field, value) ⇒ Object
27 28 29 |
# File 'lib/tire/search/query.rb', line 27 def range(field, value) @value = { :range => { field => value } } end |
#string(value, options = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/tire/search/query.rb', line 38 def string(value, ={}) @value = { :query_string => { :query => value } } @value[:query_string].update() @value end |
#term(field, value, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/tire/search/query.rb', line 12 def term(field, value, ={}) query = if value.is_a?(Hash) { field => value.to_hash } else { field => { :term => value }.update() } end @value = { :term => query } end |
#terms(field, value, options = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/tire/search/query.rb', line 21 def terms(field, value, ={}) @value = { :terms => { field => value } } @value[:terms].update( { :minimum_match => [:minimum_match] } ) if [:minimum_match] @value end |
#text(field, value, options = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/tire/search/query.rb', line 31 def text(field, value, ={}) Tire.warn "The 'text' query has been deprecated, please use a 'match' query." = { :query => value }.update() @value = { :text => { field => } } @value end |
#to_hash ⇒ Object
108 109 110 |
# File 'lib/tire/search/query.rb', line 108 def to_hash @value end |
#to_json(options = {}) ⇒ Object
112 113 114 |
# File 'lib/tire/search/query.rb', line 112 def to_json(={}) to_hash.to_json end |