Module: Mongoid::Haystack::Stemming

Extended by:
Stemming
Included in:
Stemming
Defined in:
lib/mongoid-haystack/stemming.rb

Defined Under Namespace

Modules: Stopwords

Instance Method Summary collapse

Instance Method Details

#stem(*args, &block) ⇒ Object Also known as: for



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mongoid-haystack/stemming.rb', line 6

def stem(*args, &block)
  words = args.join(' ').strip.split(/\s+/)
  list = []

  words.each do |word|
    stem = word.stem.downcase
    next if Stopwords.stopword?(word)
    next if Stopwords.stopword?(stem)
    block ? block.call(stem) : list.push(stem)
  end

  block ? nil : list
end