Class: Daedal::Queries::TermQuery

Inherits:
Query
  • Object
show all
Defined in:
lib/daedal/queries/term_query.rb

Instance Method Summary collapse

Methods inherited from Query

#to_json

Constructor Details

#initialize(options = {}) ⇒ TermQuery

Returns a new instance of TermQuery.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/daedal/queries/term_query.rb', line 16

def initialize(options={})
  super options

  if value.nil? && term.nil?
    raise "Must give a value or a term"
  elsif value && term
    raise "Use either Value or Term only, but not both"
  elsif value && boost.nil?
    raise "Please specified boost"
  end

end

Instance Method Details

#to_hashObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/daedal/queries/term_query.rb', line 29

def to_hash
  if boost
    if value
      result = {term: {field => {value: value, boost: boost}}}
    else
      result = {term: {field => {term: term, boost: boost}}}
    end
  else
    result = {term: {field => term}}
  end

  result
end