Class: Picky::Query::Combination

Inherits:
Object
  • Object
show all
Defined in:
lib/picky/query/combination.rb,
lib/picky/query/combination/or.rb

Overview

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.

Direct Known Subclasses

Or

Defined Under Namespace

Classes: Or

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, category, weight) ⇒ Combination

Returns a new instance of Combination.



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

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

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



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

def category
  @category
end

#tokenObject (readonly)

Returns the value of attribute token.



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

def token
  @token
end

#weightObject (readonly)

Returns the weight of this combination.



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

def weight
  @weight
end

Instance Method Details

#bundleObject



33
34
35
# File 'lib/picky/query/combination.rb', line 33

def bundle
  category.bundle_for token
end

#category_nameObject

Returns the category’s name. Used in boosting.



27
28
29
# File 'lib/picky/query/combination.rb', line 27

def category_name
  @category_name ||= category.name
end

#identifierObject

The identifier for this combination.



53
54
55
# File 'lib/picky/query/combination.rb', line 53

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

#idsObject

Returns an array of ids for the given text.

Note: Caching is most of the time useful.



47
48
49
# File 'lib/picky/query/combination.rb', line 47

def ids
  @ids ||= category.ids(token)
end

#to_resultObject

Combines the category names with the original names. [

[:title,    'Flarbl', :flarbl],
[:category, 'Gnorf',  :gnorf]

]



63
64
65
# File 'lib/picky/query/combination.rb', line 63

def to_result
  [category_name, *token.to_result]
end

#to_sObject

Example:

"exact title:Peter*:peter"


70
71
72
# File 'lib/picky/query/combination.rb', line 70

def to_s
  "(#{category.bundle_for(token).identifier},#{to_result.join(':')})"
end