lib/picky/internals/query/indexes.rb in picky-2.1.0 vs lib/picky/internals/query/indexes.rb in picky-2.1.1

- old
+ new

@@ -23,14 +23,39 @@ def initialize *index_definitions, combinations_type @combinations_type = combinations_type @indexes = index_definitions.map &:indexed end - # Returns a number of possible allocations for the given tokens. + # Returns a number of prepared (sorted, reduced etc.) allocations for the given tokens. # - def sorted_allocations_for tokens + def prepared_allocations_for tokens, weights = {} + allocations = allocations_for tokens + # Remove double allocations. + # + allocations.uniq + + # Score the allocations using weights as bias. + # + allocations.calculate_score weights + + # Sort the allocations. + # (allocations are sorted according to score, highest to lowest) + # + allocations.sort! + + # Reduce the amount of allocations. + # + # allocations.reduce_to some_amount + + # Remove identifiers from allocations. + # + # allocations.remove some_array_of_identifiers_to_remove + + allocations end + # Returns a number of possible allocations for the given tokens. + # def allocations_for tokens Allocations.new allocations_ary_for(tokens) end def allocations_ary_for tokens indexes.inject([]) do |allocations, index| \ No newline at end of file