lib/picky/query/indexes.rb in picky-3.1.2 vs lib/picky/query/indexes.rb in picky-3.1.3

- old
+ new

@@ -11,32 +11,49 @@ # # What it does is take the three given (API-) indexes and # # bundle them in an index bundle. # class Indexes - attr_reader :indexes + attr_reader :indexes, + :ignored_categories # Creates a new Query::Indexes. # # Its job is to generate all possible combinations. # Note: We cannot mix memory and redis indexes just yet. # def initialize *indexes IndexesCheck.check_backend_types indexes @indexes = indexes - @mapper = Query::QualifierCategoryMapper.new + map_categories 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 + # ignore :name, :first_name + # end + # + # Cleans up / optimizes after being called. + # + def ignore *qualifiers + @ignored_categories ||= [] + @ignored_categories += qualifiers.map { |qualifier| @mapper.map qualifier }.compact + @ignored_categories.uniq! + end + # Returns a number of prepared (sorted, reduced etc.) allocations for the given tokens. # def prepared_allocations_for tokens, weights = {} allocations = allocations_for tokens @@ -55,12 +72,12 @@ # Reduce the amount of allocations. # # allocations.reduce_to some_amount - # Remove identifiers from allocations. + # Remove categories from allocations. # - # allocations.remove some_array_of_identifiers_to_remove + allocations.remove ignored_categories if ignored_categories allocations end # Returns a number of possible allocations for the given tokens. # \ No newline at end of file