Class: XapianDb::Repositories::Stopper
- Inherits:
-
Object
- Object
- XapianDb::Repositories::Stopper
- Defined in:
- lib/xapian_db/repositories/stopper.rb
Overview
The stopper is a repository that manages stoppers for the supported languges
Class Method Summary collapse
-
.stopper_for(iso_cd) ⇒ Xapian::SimpleStopper
Get or build the stopper for a language.
Class Method Details
.stopper_for(iso_cd) ⇒ Xapian::SimpleStopper
Get or build the stopper for a language
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/xapian_db/repositories/stopper.rb', line 16 def stopper_for(iso_cd) @stoppers ||= {} return nil if iso_cd.nil? key = iso_cd.to_sym # Do we already have a stopper for this language? return @stoppers[key] unless @stoppers[key].nil? # build the stopper stopper = Xapian::SimpleStopper.new stopwords_file = File.join(File.dirname(__FILE__), '../stopwords', "#{iso_cd}.txt") return nil unless File.exist? stopwords_file open(stopwords_file, "r") do |file| file.each do |word| stopper.add word.chomp end end @stoppers[key] = stopper end |