lib/picky/internals/query/indexes.rb in picky-1.5.4 vs lib/picky/internals/query/indexes.rb in picky-2.0.0.pre1

- old
+ new

@@ -1,22 +1,22 @@ module Internals module Query - + # The query indexes class bundles indexes given to a query. # # Example: # # If you call - # Query::Full.new dvd_index, mp3_index, video_index - # + # Search.new dvd_index, mp3_index, video_index + # # # What it does is take the three given (API-) indexes and # # bundle them in an index bundle. # class Indexes - + attr_reader :indexes - + # Creates a new Query::Indexes. # # Its job is to generate all possible combinations, but also # checking whether the query indexes are all of the same type. # Note: We cannot mix memory and redis indexes just yet. @@ -31,34 +31,34 @@ def allocations_for tokens Allocations.new(indexes.inject([]) do |previous_allocations, index| # Expand the combinations. # possible_combinations = tokens.possible_combinations_in index - + # Optimization for ignoring tokens that allocate to nothing and # can be ignored. # For example in a special search, where "florian" is not # mapped to any category. # possible_combinations.compact! - + # Generate all possible combinations. # expanded_combinations = expand_combinations_from possible_combinations - + # If there are none, try the next allocation. # next previous_allocations unless expanded_combinations - + # Add the wrapped possible allocations to the ones we already have. # previous_allocations + expanded_combinations.map! do |expanded_combination| @combinations_type.new(expanded_combination).pack_into_allocation(index.result_identifier) # TODO Do not extract result_identifier. Remove pack_into_allocation. end end) end - + # This is the core of the search engine. # # Gets an array of # [ # [<combinations for token1>], @@ -116,11 +116,11 @@ def expand_combinations_from possible_combinations # If an element has size 0, this means one of the # tokens could not be allocated. # return if possible_combinations.any?(&:empty?) - + # Generate the first multiplicator "with which" (well, not quite) to multiply the smallest amount of combinations. # single_mult = possible_combinations.inject(1) { |total, combinations| total * combinations.size } # Initialize a group multiplicator. @@ -129,11 +129,11 @@ # The expanding part to line up the combinations # for later combination in allocations. # possible_combinations.collect! do |combinations| - + # Get the size of the combinations of the first token. # combinations_size = combinations.size # Special case: If there is no combination for one of the tokens. @@ -141,37 +141,37 @@ # the next iteration. # If there are combinations, we divide the single mult # by the number of combinations. # single_mult /= combinations_size unless combinations_size.zero? - + # Expand each combination by the single mult: # [a,b,c] # [a,a,a, b,b,b, c,c,c] # Then, expand the result by the group mult: # [a,a,a,b,b,b,c,c,c, a,a,a,b,b,b,c,c,c, a,a,a,b,b,b,c,c,c] # combinations = combinations.inject([]) do |total, combination| total + Array.new(single_mult, combination) end * group_mult - + # Multiply the group mult by the combinations size, # since the next combinations' single mult is smaller # and we need to adjust for that. # group_mult = group_mult * combinations_size - + # Return the combinations. # combinations end - + return if possible_combinations.empty? - + possible_combinations.shift.zip *possible_combinations end - + end - + end - + end \ No newline at end of file