Class: Tire::Search::MatchQuery

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, value, options = {}) ⇒ MatchQuery

Returns a new instance of MatchQuery.



16
17
18
19
20
21
22
23
24
# File 'lib/tire/search/queries/match.rb', line 16

def initialize(field, value, options={})
  query_options = { :query => value }.merge(options)

  if field.is_a?(Array)
    @value = { :multi_match => query_options.merge( :fields => field ) }
  else
    @value = { :match => { field => query_options } }
  end
end

Class Method Details

.add(query, field, value, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/tire/search/queries/match.rb', line 26

def self.add(query, field, value, options={})
  unless query.value[:bool]
    original_value = query.value.dup
    query.value = { :bool => {} }
    (query.value[:bool][:must] ||= []) << original_value
  end
  query.value[:bool][:must] << MatchQuery.new(field, value, options).to_hash
end

Instance Method Details

#to_hashObject



35
36
37
# File 'lib/tire/search/queries/match.rb', line 35

def to_hash
  @value
end