Class: Stretchy::Queries::MatchQuery

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

Constant Summary collapse

OPERATORS =
['and', 'or']
MATCH_TYPES =
['phrase', 'phrase_prefix']

Instance Method Summary collapse

Methods included from Utils::Validation

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

Instance Method Details

#after_initialize(params) ⇒ Object



29
30
31
# File 'lib/stretchy/queries/match_query.rb', line 29

def after_initialize(params)
  @min ||= params[:minimum_should_match]
end

#option_attributesObject



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

def option_attributes
  return @opts if @opts
  @opts = {}
  @opts[:query]                = @string
  @opts[:type]                 = @type       if @type
  @opts[:operator]             = @operator   if @operator
  @opts[:minimum_should_match] = @min        if @min
  @opts[:slop]                 = @slop       if @slop && MATCH_TYPES.include?(@type)
  @opts[:max_expansions]       = @max        if @max && @type == 'phrase_prefix'
  @opts
end

#to_searchObject



45
46
47
48
49
50
51
# File 'lib/stretchy/queries/match_query.rb', line 45

def to_search
  {
    match: {
      @field => option_attributes,
    }
  }
end