lib/picky/search.rb in picky-4.0.0pre6 vs lib/picky/search.rb in picky-4.0.0
- old
+ new
@@ -13,37 +13,39 @@
# We recommend to not use this directly, but connect it to an URL and query through one of these
# (Protip: Use "curl 'localhost:8080/query/path?query=exampletext')" in a Terminal.
#
class Search
+ include API::Search::Boost
+
include Helpers::Measuring
attr_reader :indexes
attr_accessor :tokenizer,
- :weights
+ :boosts
delegate :ignore,
:to => :indexes
# Takes:
# * A number of indexes
#
- # It is also possible to define the tokenizer and weights like so.
+ # It is also possible to define the tokenizer and boosts like so.
# Example:
# search = Search.new(index1, index2, index3) do
# searching removes_characters: /[^a-z]/ # etc.
- # weights [:author, :title] => +3,
+ # boosts [:author, :title] => +3,
# [:title, :isbn] => +1
# end
#
def initialize *index_definitions
@indexes = Query::Indexes.new *index_definitions
instance_eval(&Proc.new) if block_given?
@tokenizer ||= Tokenizer.searching # THINK Not dynamic. Ok?
- @weights ||= Query::Weights.new
+ @boosts ||= Query::Boosts.new
@ignore_unassigned = false if @ignore_unassigned.nil?
self
end
@@ -85,11 +87,11 @@
# (As Picky needs to calculate the total)
#
# Note: When using the Picky interface, do not terminate too
# early as this will kill off the allocation selections.
# A value of
- # early_terminate 5
+ # terminate_early 5
# is probably a good idea to show the user 5 extra
# beyond the needed ones.
#
# Examples:
# # Terminate if you have enough ids.
@@ -115,33 +117,29 @@
# [:title, :isbn] => +1
# end
#
# or
#
- # # Explicitly add a random number (0...1) to the weights.
+ # # Explicitly add a random number (0...1) to the boosts.
# #
- # my_weights = Class.new do
+ # my_boosts = Class.new do
# # Instance only needs to implement
- # # score_for combinations
+ # # boost_for combinations
# # and return a number that is
- # # added to the weight.
+ # # added to the score.
# #
- # def score_for combinations
+ # def boost_for combinations
# rand
# end
# end.new
#
# search = Search.new(books_index, dvd_index, mp3_index) do
- # boost my_weights
+ # boost my_boosts
# end
#
- def boost weights
- @weights = if weights.respond_to?(:score_for)
- weights
- else
- Query::Weights.new weights
- end
+ def boost boosts
+ @boosts = extract_boosts boosts
end
# Ignore the given token if it cannot be matched to a category.
# The default behaviour is that if a token does not match to
# any category, the query will not return anything (since a
@@ -223,19 +221,19 @@
end
# Gets sorted allocations for the tokens.
#
def sorted_allocations tokens, amount = nil # :nodoc:
- indexes.prepared_allocations_for tokens, weights, amount
+ indexes.prepared_allocations_for tokens, boosts, amount
end
# Display some nice information for the user.
#
def to_s
s = "#{self.class}("
ary = []
ary << @indexes.indexes.map(&:name).join(', ') unless @indexes.indexes.empty?
- ary << "weights: #{@weights}" if @weights
+ ary << "boosts: #{@boosts}" if @boosts
s << ary.join(', ')
s << ")"
s
end
\ No newline at end of file