Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

94 lines (75 sloc) 2.128 kb
# encoding: utf-8
#
module Picky
# Rename Picky::ExactFirst?
#
module Wrappers
module Category
# This index combines an exact and partial index.
# It serves to order the results such that exact hits are found first.
#
class ExactFirst
# TODO Refactor! (Subclass Picky::Category? Or better yet, extend Picky::Category?)
#
delegate :add,
:qualifiers,
:exact,
:partial,
:replace,
:identifier,
:name,
:index,
:category,
:dump,
:load,
:empty,
:prepared_index_file,
:tokenizer,
:cache,
:from,
:bundle_for,
:build_realtime_mapping,
:to => :@category
def initialize category
@category = category
@exact = category.exact
@partial = category.partial
end
def self.wrap index_or_category
if index_or_category.respond_to? :categories
wrap_each_of index_or_category.categories
index_or_category
else
new index_or_category
end
end
def self.wrap_each_of categories
actual_categories = categories.categories
categories.clear_categories
actual_categories.each do |category|
categories << new(category)
end
end
def ids token
text = token.text
if token.partial?
@exact.ids(text) | @partial.ids(text)
else
@exact.ids text
end
end
def weight token
text = token.text
if token.partial?
[@exact.weight(text), @partial.weight(text)].compact.max
else
@exact.weight text
end
end
def combination_for token
weight(token) && Query::Combination.new(token, self)
end
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.