lib/picky/query/indexes.rb in picky-4.0.4 vs lib/picky/query/indexes.rb in picky-4.0.5
- old
+ new
@@ -23,21 +23,13 @@
#
def initialize *indexes
IndexesCheck.check_backends indexes
@indexes = indexes
-
- map_categories
+
+ @mapper = QualifierCategoryMapper.new indexes # TODO Move out?
end
- def map_categories
- @mapper = Query::QualifierCategoryMapper.new
- @indexes.each do |index|
- index.each_category do |category|
- @mapper.add category
- end
- end
- end
# Ignore the categories with these qualifiers.
#
# Example:
# search = Search.new(index1, index2, index3) do
@@ -48,9 +40,22 @@
#
def ignore *qualifiers
@ignored_categories ||= []
@ignored_categories += qualifiers.map { |qualifier| @mapper.map qualifier }.compact
@ignored_categories.uniq!
+ end
+
+ # Restrict categories to the given ones.
+ #
+ # Functionally equivalent as if indexes didn't
+ # have the categories at all.
+ #
+ # Note: Probably only makes sense when an index
+ # is used in multiple searches. If not, why even
+ # have the categories?
+ #
+ def only *qualifiers
+ @mapper.restrict_to *qualifiers
end
# Returns a number of prepared (sorted, reduced etc.) allocations for the given tokens.
#
def prepared_allocations_for tokens, weights = {}, amount = nil
\ No newline at end of file