Class: XapianDb::Repositories::Stemmer

Inherits:
Object
  • Object
show all
Defined in:
lib/xapian_db/repositories/stemmer.rb

Overview

The stemmer is a repository that manages stemmers for the supported languges

Author:

  • Gernot Kogler

Class Method Summary collapse

Class Method Details

.stemmer_for(iso_cd) ⇒ Xapian::Stem

Get or build the stemmer for a language

Parameters:

  • iso_cd (Symbol, String)

    The iso code for the language (:en, :de …)

Returns:

  • (Xapian::Stem)

    The Stemmer for this lanugage


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xapian_db/repositories/stemmer.rb', line 16

def stemmer_for(iso_cd)
  @stemmers ||= {}
  return nil if iso_cd.nil?
  key = iso_cd.to_sym

  # Do we already have a stemmer for this language?
  return @stemmers[key] unless @stemmers[key].nil?

  # Do we support this language?
  unless (LANGUAGE_MAP.keys + [:none]).include?(key)
    raise ArgumentError.new "Language #{iso_cd} is not supported by XapianDb (remember to use the language iso codes)"
  end

  # Let's build the stemmer
  @stemmers[key] = Xapian::Stem.new(key.to_s)
end