Class: Stretchy::Queries::MatchQuery

Inherits:
Base
  • Object
show all
Defined in:
lib/stretchy/queries/match_query.rb

Constant Summary collapse

OPERATORS =
['and', 'or']

Constants included from Utils::Contract

Utils::Contract::ASSERTIONS, Utils::Contract::DECAY_FUNCTIONS, Utils::Contract::DISTANCE_FORMAT

Instance Method Summary collapse

Methods included from Utils::Contract

included, #require_one, #validate!

Constructor Details

#initialize(options = {}) ⇒ MatchQuery

Returns a new instance of MatchQuery.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/stretchy/queries/match_query.rb', line 13

def initialize(options = {})
  case options
  when String
    @field    = '_all'
    @string   = options
    @operator = 'and'
  when Hash
    @field    = options[:field]    || '_all'
    @string   = options[:string]
    @operator = options[:operator] || 'and'
  end
  validate!
end

Instance Method Details

#to_searchObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/stretchy/queries/match_query.rb', line 27

def to_search
  {
    match: {
      @field => {
        query:    @string,
        operator: @operator
      }
    }
  }
end