Class: Qiita::Elasticsearch::MatchableToken

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

Constant Summary collapse

RELATIVE_BEST_FIELDS_QUERY_WEIGHT =
0.5

Instance Attribute Summary collapse

Attributes inherited from Token

#field_name, #options, #term

Instance Method Summary collapse

Methods inherited from Token

#downcased?, #downcased_term, #filter?, #initialize, #must?, #must_not?, #negative?, #or?, #positive?, #proper_cased_term, #query?, #quoted?, #sort?, #to_s, #type?

Constructor Details

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

Instance Attribute Details

#default_fields=(value) ⇒ Object (writeonly)

Sets the attribute default_fields

Parameters:

  • value

    the value to set the attribute default_fields to.



8
9
10
# File 'lib/qiita/elasticsearch/matchable_token.rb', line 8

def default_fields=(value)
  @default_fields = value
end

#field_mappingObject

Returns the value of attribute field_mapping.



9
10
11
# File 'lib/qiita/elasticsearch/matchable_token.rb', line 9

def field_mapping
  @field_mapping
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


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

def to_hash
  if quoted?
    build_multi_match_query(type: "phrase")
  else
    {
      "bool" => {
        "should" => [
          build_multi_match_query(type: "phrase"),
          build_multi_match_query(type: "best_fields", boost: RELATIVE_BEST_FIELDS_QUERY_WEIGHT),
        ],
      },
    }
  end
end