Class: Elasticquery::Queries::MultiMatch

Inherits:
Base
  • Object
show all
Defined in:
lib/elasticquery/queries/multi_match.rb

Constant Summary collapse

OPERATORS =
%w(and or)
TYPES =
%w(best_fields most_fields cross_fields phrase pharse_prefix)

Instance Method Summary collapse

Methods inherited from Base

#invalid?

Constructor Details

#initialize(query, fields: "_all", operator: "and", type: "best_fields") ⇒ MultiMatch



9
10
11
12
13
14
# File 'lib/elasticquery/queries/multi_match.rb', line 9

def initialize(query, fields: "_all", operator: "and", type: "best_fields")
  @fields = fields
  @operator = operator
  @type = type
  @query = query
end

Instance Method Details

#to_hashObject



23
24
25
# File 'lib/elasticquery/queries/multi_match.rb', line 23

def to_hash
  {multi_match: subquery}
end

#valid?Boolean



16
17
18
19
20
21
# File 'lib/elasticquery/queries/multi_match.rb', line 16

def valid?
  OPERATORS.include?(@operator) &&
    TYPES.include?(@type) &&
    @query.present? &&
    ( Array === @fields || @fields == "_all" )
end