Sha256: ca67bef865408ee929f47ad4d4013f2428de39bbdec6c21973a73241858d939e

Contents?: true

Size: 1.54 KB

Versions: 36

Compression:

Stored size: 1.54 KB

Contents

module Picky

  module Query

    # Describes the Combination of:
    #  * a token
    #  * a category
    #  * the weight of the token in the category (cached from earlier)
    #
    # An Allocation consists of an ordered number of Combinations.
    #
    class Combination

      attr_reader :token,
                  :category,
                  :weight

      def initialize token, category, weight
        @token    = token
        @category = category
        @weight   = weight
      end

      # Returns the category's name.
      # Used in boosting.
      #
      def category_name
        @category_name ||= category.name
      end

      #
      #
      def bundle
        category.bundle_for token
      end

      # Returns the weight of this combination.
      #
      def weight
        @weight
      end

      # Returns an array of ids for the given text.
      #
      # Note: Caching is most of the time useful.
      #
      def ids
        @ids ||= category.ids(token)
      end

      # The identifier for this combination.
      #
      def identifier
        @identifier ||= "#{bundle.identifier}:inverted:#{token.text}"
      end

      # Combines the category names with the original names.
      # [
      #  [:title,    'Flarbl', :flarbl],
      #  [:category, 'Gnorf',  :gnorf]
      # ]
      #
      def to_result
        [category_name, *token.to_result]
      end

      # Example:
      #   "exact title:Peter*:peter"
      #
      def to_s
        "(#{category.bundle_for(token).identifier},#{to_result.join(':')})"
      end

    end

  end

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
picky-4.31.3 lib/picky/query/combination.rb
picky-4.31.2 lib/picky/query/combination.rb
picky-4.31.1 lib/picky/query/combination.rb
picky-4.31.0 lib/picky/query/combination.rb
picky-4.30.0 lib/picky/query/combination.rb
picky-4.29.0 lib/picky/query/combination.rb
picky-4.28.1 lib/picky/query/combination.rb
picky-4.27.1 lib/picky/query/combination.rb
picky-4.27.0 lib/picky/query/combination.rb
picky-4.26.2 lib/picky/query/combination.rb
picky-4.26.1 lib/picky/query/combination.rb
picky-4.26.0 lib/picky/query/combination.rb
picky-4.25.3 lib/picky/query/combination.rb
picky-4.25.2 lib/picky/query/combination.rb
picky-4.25.1 lib/picky/query/combination.rb
picky-4.25.0 lib/picky/query/combination.rb
picky-4.24.0 lib/picky/query/combination.rb
picky-4.23.2 lib/picky/query/combination.rb
picky-4.23.1 lib/picky/query/combination.rb
picky-4.23.0 lib/picky/query/combination.rb