lib/picky/search.rb in picky-3.6.7 vs lib/picky/search.rb in picky-3.6.8
- old
+ new
@@ -47,10 +47,12 @@
@ignore_unassigned = false if @ignore_unassigned.nil?
self
end
+ # Defines tokenizer options or the tokenizer itself.
+ #
# Examples:
# search = Search.new(index1, index2, index3) do
# searching removes_characters: /[^a-z]/,
# # etc.
# end
@@ -65,11 +67,22 @@
else
options && Tokenizer.new(options)
end
end
+ # Sets the max amount of allocations to calculate.
+ #
# Examples:
+ # search = Search.new(index1, index2, index3) do
+ # max_allocations 10
+ # end
+ #
+ def max_allocations amount = nil
+ amount ? @max_allocations = amount : @max_allocations
+ end
+
+ # Examples:
# search = Search.new(books_index, dvd_index, mp3_index) do
# boost [:author, :title] => +3,
# [:title, :isbn] => +1
# end
#
@@ -159,11 +172,11 @@
# Execute a search using Query::Tokens.
#
# Note: Internal method, use #search to search.
#
def execute tokens, ids, offset, original_text = nil
- Results.from original_text, ids, offset, sorted_allocations(tokens)
+ Results.from original_text, ids, offset, sorted_allocations(tokens, @max_allocations)
end
# Delegates the tokenizing to the query tokenizer.
#
# Parameters:
@@ -180,22 +193,21 @@
tokens
end
# Gets sorted allocations for the tokens.
#
- def sorted_allocations tokens # :nodoc:
- indexes.prepared_allocations_for tokens, weights
+ def sorted_allocations tokens, amount = nil # :nodoc:
+ indexes.prepared_allocations_for tokens, weights, amount
end
# Display some nice information for the user.
#
def to_s
s = "#{self.class}("
- unless @indexes.indexes.empty?
- s << @indexes.indexes.map(&:name).join(', ')
- s << ", "
- end
- s << "weights: #{@weights}"
+ ary = []
+ ary << @indexes.indexes.map(&:name).join(', ') unless @indexes.indexes.empty?
+ ary << "weights: #{@weights}" if @weights
+ s << ary.join(', ')
s << ")"
s
end
end
\ No newline at end of file