Sha256: fbc97903b1bf8119492e411a5cb9222daed4080fc0bca6cca2136efce8e2784d

Contents?: true

Size: 1.79 KB

Versions: 63

Compression:

Stored size: 1.79 KB

Contents

module Sunspot
  module DSL #:nodoc:
    #
    # This class provides the DSL for MoreLikeThis queries.
    #
    class MoreLikeThisQuery < FieldQuery
      include Paginatable, Adjustable

      def fields(*field_names)
        boosted_fields = field_names.pop if field_names.last.is_a?(Hash)
        field_names.each do |name|
          mlt_fields = @setup.more_like_this_fields(name)
          raise(ArgumentError, "Field #{name} is not setup for more_like_this") if mlt_fields.empty?
          mlt_fields.each { |field| @query.more_like_this.add_field(field) }
        end
        if boosted_fields
          boosted_fields.each_pair do |field_name, boost|
            @setup.more_like_this_fields(field_name).each do |field|
              @query.more_like_this.add_field(field, boost)
            end
          end
        end
      end

      def minimum_term_frequency(value)
        @query.more_like_this.minimum_term_frequency = value
      end
      alias_method :mintf, :minimum_term_frequency
      
      def minimum_document_frequency(value)
        @query.more_like_this.minimum_document_frequency = value
      end
      alias_method :mindf, :minimum_document_frequency

      def minimum_word_length(value)
        @query.more_like_this.minimum_word_length = value
      end
      alias_method :minwl, :minimum_word_length

      def maximum_word_length(value)
        @query.more_like_this.maximum_word_length = value
      end
      alias_method :maxwl, :maximum_word_length
      
      def maximum_query_terms(value)
        @query.more_like_this.maximum_query_terms = value
      end
      alias_method :maxqt, :maximum_query_terms

      def boost_by_relevance(should_boost)
        @query.more_like_this.boost_by_relevance = should_boost
      end
      alias_method :boost, :boost_by_relevance
    end
  end
end

Version data entries

63 entries across 63 versions & 12 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.7.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.6.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.5.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.4.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.3.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.8 lib/sunspot/dsl/more_like_this_query.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.7 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.6 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.5 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.4 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.3 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.2 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.1 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.2.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.1.1 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.1.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.0.0 lib/sunspot/dsl/more_like_this_query.rb
sunspot-2.0.0.pre.130115 lib/sunspot/dsl/more_like_this_query.rb