Class: MiniSearch::StemmerFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_search/stemmer_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(stemmer) ⇒ StemmerFilter

Returns a new instance of StemmerFilter.



5
6
7
# File 'lib/mini_search/stemmer_filter.rb', line 5

def initialize(stemmer)
  @stemmer = stemmer
end

Instance Method Details

#execute(tokens) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/mini_search/stemmer_filter.rb', line 9

def execute(tokens)
  return tokens unless @stemmer

  new_tokens = tokens.map do |token|
    @stemmer.stem(token)
  end

  (new_tokens + tokens).uniq
end