Class: Stretchy::Queries::MatchQuery

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

Constant Summary collapse

OPERATORS =
['and', 'or']

Instance Method Summary collapse

Methods included from Utils::Validation

#errors, included, #require_one!, #require_only_one!, #valid?, #validate!, #validator

Constructor Details

#initialize(options = {}) ⇒ MatchQuery

Returns a new instance of MatchQuery.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stretchy/queries/match_query.rb', line 20

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



34
35
36
37
38
39
40
41
42
43
# File 'lib/stretchy/queries/match_query.rb', line 34

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