Module: Picky::Results::ExactFirst

Defined in:
lib/picky/results/exact_first.rb

Overview

This index combines an exact and partial index. It serves to order the results such that exact hits are found first.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extend_each_of(categories) ⇒ Object



23
24
25
# File 'lib/picky/results/exact_first.rb', line 23

def self.extend_each_of categories
  categories.categories.each { |category| category.extend self }
end

.extended(index_or_category) ⇒ Object

Installs the exact first on the given category or on the categories of the index, if an index is given.

THINK Can we unextend in the case it is an index?



17
18
19
20
21
22
# File 'lib/picky/results/exact_first.rb', line 17

def self.extended index_or_category
  if index_or_category.respond_to? :categories
    extend_each_of index_or_category.categories
    index_or_category
  end
end

Instance Method Details

#ids(token) ⇒ Object

Overrides the original method.



29
30
31
32
33
34
35
36
# File 'lib/picky/results/exact_first.rb', line 29

def ids token
  text = token.text
  if token.partial?
    exact.ids(text) | partial.ids(text)
  else
    exact.ids text
  end
end

#weight(token) ⇒ Object

Overrides the original method.



40
41
42
43
44
45
46
47
# File 'lib/picky/results/exact_first.rb', line 40

def weight token
  text = token.text
  if token.partial?
    [exact.weight(text), partial.weight(text)].compact.max
  else
    exact.weight text
  end
end