class Sunspot::Query::MoreLikeThis

Attributes

fields[R]

Public Instance Methods

add_field(field, boost = nil) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 16
def add_field(field, boost = nil)
  raise(ArgumentError, "Field #{field.name} is not set up for more_like_this") unless field.more_like_this?
  @fields[field.indexed_name] = TextFieldBoost.new(field, boost)
end
boost_by_relevance=(should_boost) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 41
def boost_by_relevance=(should_boost)
  @params[:"mlt.boost"] = should_boost
end
maximum_query_terms=(maxqt) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 37
def maximum_query_terms=(maxqt)
  @params[:"mlt.maxqt"] = maxqt
end
maximum_word_length=(maxwl) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 33
def maximum_word_length=(maxwl)
  @params[:"mlt.maxwl"] = maxwl
end
minimum_document_frequency=(mindf) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 25
def minimum_document_frequency=(mindf)
  @params[:"mlt.mindf"] = mindf
end
minimum_term_frequency=(mintf) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 21
def minimum_term_frequency=(mintf)
  @params[:"mlt.mintf"] = mintf
end
minimum_word_length=(minwl) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 29
def minimum_word_length=(minwl)
  @params[:"mlt.minwl"] = minwl
end
to_params() click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 45
def to_params
  params = Sunspot::Util.deep_merge(
    @params,
    :q => @document_scope.to_boolean_phrase
  )
  params[:"mlt.fl"] = @fields.keys.join(",")
  boosted_fields = @fields.values.select { |field| field.boost }
  unless boosted_fields.empty?
    params[:"mlt.qf"] = boosted_fields.map do |field|
      field.to_boosted_field
    end.join(' ')
  end
  params
end

Public Class Methods

new(document) click to toggle source
# File lib/sunspot/query/more_like_this.rb, line 6
def initialize(document)
  @document_scope = Restriction::EqualTo.new(
    false,
    IdField.instance,
    Adapters::InstanceAdapter.adapt(document).index_id
  )
  @fields = {}
  @params = {}
end