Sha256: 153307d0225d65f1bdce3c79e4319b205cc5a952cb5fa81f34f11681dc84fa41

Contents?: true

Size: 1.42 KB

Versions: 38

Compression:

Stored size: 1.42 KB

Contents

module Picky

  module Query

    class Combination
      
      # Pretends to be a combination.
      #
      # TODO Rework completely and document.
      #
      class Or < Combination
        
        def initialize combinations
          @combinations = combinations
        end
        
        # Returns the combination's category name.
        # Used in boosting.
        #
        def category_name
          @category_name ||= @combinations.map(&:category_name).join('|').intern
        end

        # Returns the total (?) weight of its combinations.
        #
        # Note: Caching is most of the time useful.
        #
        def weight
          @weight ||= @combinations.inject(0) do |sum, combination|
            sum + combination.weight
          end
        end

        # Returns an array of ids from its combinations.
        #
        # Note: Caching is most of the time useful.
        #
        def ids
          @ids ||= @combinations.inject([]) do |total, combination|
            total + combination.ids
          end.uniq
        end
        
        def identifier
          @identifier ||= "#{@combinations.map(&:bundle).map(&:identifier).join('|')}:inverted:#{token.text}"
        end
        
        def to_result
          results = @combinations.map &:to_result
          [*@combinations.map(&:to_result).transpose.map! { |thing| thing.join('|') }]
        end
        
      end
      
    end
    
  end
  
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
picky-4.22.0 lib/picky/query/combination/or.rb
picky-4.21.2 lib/picky/query/combination/or.rb
picky-4.21.1 lib/picky/query/combination/or.rb
picky-4.21.0 lib/picky/query/combination/or.rb
picky-4.20.2 lib/picky/query/combination/or.rb
picky-4.20.1 lib/picky/query/combination/or.rb
picky-4.20.0 lib/picky/query/combination/or.rb
picky-4.19.7 lib/picky/query/combination/or.rb
picky-4.19.6 lib/picky/query/combination/or.rb
picky-4.19.5 lib/picky/query/combination/or.rb
picky-4.19.4 lib/picky/query/combination/or.rb
picky-4.19.3 lib/picky/query/combination/or.rb
picky-4.19.2 lib/picky/query/combination/or.rb
picky-4.19.1 lib/picky/query/combination/or.rb
picky-4.19.0 lib/picky/query/combination/or.rb
picky-4.18.0 lib/picky/query/combination/or.rb
picky-4.17.1 lib/picky/query/combination/or.rb
picky-4.17.0 lib/picky/query/combination/or.rb