Class: Qiita::Elasticsearch::MatchableToken

Inherits:
Token
  • Object
show all
Defined in:
lib/qiita/elasticsearch/matchable_token.rb

Instance Attribute Summary collapse

Attributes inherited from Token

#field_name, #term

Instance Method Summary collapse

Methods inherited from Token

#downcased?, #downcased_term, #filter?, #ignorable?, #initialize, #must?, #must_not?, #negative?, #or?, #positive?, #proper_cased_term, #quoted?, #to_s

Constructor Details

This class inherits a constructor from Qiita::Elasticsearch::Token

Instance Attribute Details

#matchable_fields=(value) ⇒ Object (writeonly)

Sets the attribute matchable_fields

Parameters:

  • value

    the value to set the attribute matchable_fields to.



6
7
8
# File 'lib/qiita/elasticsearch/matchable_token.rb', line 6

def matchable_fields=(value)
  @matchable_fields = value
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/qiita/elasticsearch/matchable_token.rb', line 9

def to_hash
  if @matchable_fields.nil?
    {
      quoted? ? "match_phrase" : "match" => {
        "_all" => @term,
      }
    }
  else
    hash = {
      "multi_match" => {
        "fields" => @matchable_fields,
        "query" => @term,
      },
    }
    hash["multi_match"]["type"] = "phrase" if quoted?
    hash
  end
end