Class: Picky::Query::Combination::Or

Inherits:
Picky::Query::Combination show all
Defined in:
lib/picky/query/combination/or.rb

Overview

Pretends to be a combination.

TODO Rework completely and document.

Instance Attribute Summary

Attributes inherited from Picky::Query::Combination

#category, #token

Instance Method Summary collapse

Methods inherited from Picky::Query::Combination

#bundle, #to_s

Constructor Details

#initialize(combinations) ⇒ Or

Returns a new instance of Or.



13
14
15
# File 'lib/picky/query/combination/or.rb', line 13

def initialize combinations
  @combinations = combinations
end

Instance Method Details

#category_nameObject

Returns the combination’s category name. Used in boosting.



20
21
22
# File 'lib/picky/query/combination/or.rb', line 20

def category_name
  @category_name ||= @combinations.map(&:category_name).join('|').intern
end

#identifierObject



44
45
46
# File 'lib/picky/query/combination/or.rb', line 44

def identifier
  @identifier ||= "#{@combinations.map(&:bundle).map(&:identifier).join('|')}:inverted:#{token.text}"
end

#idsObject

Returns an array of ids from its combinations.

Note: Caching is most of the time useful.



38
39
40
41
42
# File 'lib/picky/query/combination/or.rb', line 38

def ids
  @ids ||= @combinations.inject([]) do |total, combination|
    total + combination.ids
  end.uniq
end

#to_resultObject



48
49
50
51
# File 'lib/picky/query/combination/or.rb', line 48

def to_result
  results = @combinations.map &:to_result
  [*@combinations.map(&:to_result).transpose.map! { |thing| thing.join('|') }]
end

#weightObject

Returns the total (?) weight of its combinations.

Note: Caching is most of the time useful.



28
29
30
31
32
# File 'lib/picky/query/combination/or.rb', line 28

def weight
  @weight ||= @combinations.inject(0) do |sum, combination|
    sum + combination.weight
  end
end