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::DISTANCE_FORMAT

Instance Method Summary collapse

Methods included from Utils::Contract

included, #validate!

Constructor Details

#initialize(string, field: '_all', operator: 'and') ⇒ MatchQuery

Returns a new instance of MatchQuery.



11
12
13
14
15
16
# File 'lib/stretchy/queries/match_query.rb', line 11

def initialize(string, field: '_all', operator: 'and')
  @field    = field
  @operator = operator
  @string   = string
  validate!
end

Instance Method Details

#to_searchObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/stretchy/queries/match_query.rb', line 18

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