Skip to content

Commit

Permalink
Silently ignore stemming unsupported language words
Browse files Browse the repository at this point in the history
  • Loading branch information
semaperepelitsa committed Jan 9, 2012
1 parent 70ca0ab commit e265140
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/mongoid_search/stemmers.rb
Expand Up @@ -11,10 +11,16 @@ def call(word)
class LinguaStemmer
def initialize(*args, &block)
@stemmer = ::Lingua::Stemmer.new(*args, &block)
rescue Lingua::StemmerError => e
raise unless e.message.include?("not available")
end

def call(word)
@stemmer.stem(word)
if @stemmer
@stemmer.stem(word)
else
word
end
end
end
end
4 changes: 4 additions & 0 deletions spec/util_spec.rb
Expand Up @@ -44,6 +44,10 @@
Util.normalize_keywords('Города в России бывают очень красивыми', MongoidSearch::LinguaStemmer.new(:language => 'ru'), "").should == %w( город росс быва очен красив )
end

it "should not stem unsupported-language keywords with ruby-stemmer" do
Util.normalize_keywords("Bakı", MongoidSearch::LinguaStemmer.new(:language => 'az'), "").should == ["bakı"]
end

it "should ignore keywords from ignore list" do
Util.normalize_keywords("An amazing awesome runner running and eating", MongoidSearch::FastStemmer.new, YAML.load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))["ignorelist"]).should == ["an", "runner", "run", "and", "eat"]
end
Expand Down

0 comments on commit e265140

Please sign in to comment.