lib/picky/internals/query/indexes.rb in picky-2.0.0 vs lib/picky/internals/query/indexes.rb in picky-2.1.0
- old
+ new
@@ -25,10 +25,13 @@
@indexes = index_definitions.map &:indexed
end
# Returns a number of possible allocations for the given tokens.
#
+ def sorted_allocations_for tokens
+
+ end
def allocations_for tokens
Allocations.new allocations_ary_for(tokens)
end
def allocations_ary_for tokens
indexes.inject([]) do |allocations, index|
@@ -38,33 +41,22 @@
def allocation_for tokens, 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.
- #
- return [] unless expanded_combinations
-
# Add the wrapped possible allocations to the ones we already have.
#
expanded_combinations.map! do |expanded_combination|
Allocation.new @combinations_type.new(expanded_combination), index.result_identifier # TODO Do not extract result_identifier.
end
end
- # This is the core of the search engine.
+ # This is the core of the search engine. No kidding.
#
# Gets an array of
# [
# [<combinations for token1>],
# [<combinations for token2>],
@@ -120,11 +112,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?)
+ 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 }
@@ -168,10 +160,10 @@
# Return the combinations.
#
combinations
end
- return if possible_combinations.empty?
+ return [] if possible_combinations.empty?
possible_combinations.shift.zip *possible_combinations
end
end
\ No newline at end of file