class Qiita::Elasticsearch::MatchableToken

Constants

RELATIVE_BEST_FIELDS_QUERY_WEIGHT

Attributes

default_fields[W]
field_mapping[RW]

Public Instance Methods

to_hash() click to toggle source

@return [Hash]

# 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

Private Instance Methods

build_multi_match_query(type: nil, boost: 1) click to toggle source

@return [Hash]

# File lib/qiita/elasticsearch/matchable_token.rb, line 30
def build_multi_match_query(type: nil, boost: 1)
  { "multi_match" => build_query(boost, type) }
end
build_query(boost, type) click to toggle source
# File lib/qiita/elasticsearch/matchable_token.rb, line 34
def build_query(boost, type)
  query = {
    "boost" => boost,
    "fields" => matchable_fields,
    "query" => @term,
    "type" => type,
  }
  query.merge!(options)
end
field_aliases() click to toggle source
# File lib/qiita/elasticsearch/matchable_token.rb, line 58
def field_aliases
  field_mapping[field_name]
end
matchable_fields() click to toggle source
# File lib/qiita/elasticsearch/matchable_token.rb, line 44
def matchable_fields
  if field_name
    target_fields
  elsif @default_fields && !@default_fields.empty?
    @default_fields
  else
    ["_all"]
  end
end
target_fields() click to toggle source
# File lib/qiita/elasticsearch/matchable_token.rb, line 54
def target_fields
  @target_fields ||= field_aliases ? field_aliases : [field_name]
end