Class: Picky::Query::Combination
- 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
Defined Under Namespace
Classes: Or
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#weight ⇒ Object
readonly
Returns the weight of this combination.
Instance Method Summary collapse
- #bundle ⇒ Object
-
#category_name ⇒ Object
Returns the category’s name.
-
#identifier ⇒ Object
The identifier for this combination.
-
#ids ⇒ Object
Returns an array of ids for the given text.
-
#initialize(token, category, weight) ⇒ Combination
constructor
A new instance of Combination.
-
#to_result ⇒ Object
Combines the category names with the original names.
-
#to_s ⇒ Object
Example: “exact title:Peter*:peter”.
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
#category ⇒ Object (readonly)
Returns the value of attribute category.
14 15 16 |
# File 'lib/picky/query/combination.rb', line 14 def category @category end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
14 15 16 |
# File 'lib/picky/query/combination.rb', line 14 def token @token end |
#weight ⇒ Object (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
#bundle ⇒ Object
33 34 35 |
# File 'lib/picky/query/combination.rb', line 33 def bundle category.bundle_for token end |
#category_name ⇒ Object
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 |
#identifier ⇒ Object
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 |
#ids ⇒ Object
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_result ⇒ Object
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_s ⇒ Object
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 |