have the xapian stemmer use a language based on LANG
authorJoey Hess <joey@kodama.kitenet.net>
Wed, 4 Jun 2008 06:41:02 +0000 (02:41 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Wed, 4 Jun 2008 06:41:02 +0000 (02:41 -0400)
IkiWiki/Plugin/search.pm

index 5e1d98a7248a643d438bfb88086c3ac2d906df5a..14bdb8dbc2651c2ae2ec7174e92cad738878a5c2 100644 (file)
@@ -54,6 +54,7 @@ sub pagetemplate (@) { #{{{
 } #}}}
 
 my $scrubber;
+my $stemmer;
 sub index (@) { #{{{
        my %params=@_;
        
@@ -105,7 +106,15 @@ sub index (@) { #{{{
        );
 
        my $tg = Search::Xapian::TermGenerator->new();
-       $tg->set_stemmer(new Search::Xapian::Stem("english"));
+       if (! $stemmer) {
+               my $langcode=$ENV{LANG} || "en";
+               $langcode=~s/_.*//;
+               eval { $stemmer=Search::Xapian::Stem->new($langcode) };
+               if ($@) {
+                       $stemmer=Search::Xapian::Stem->new("english");
+               }
+       }
+       $tg->set_stemmer($stemmer);
        $tg->set_document($doc);
        $tg->index_text($params{page}, 2);
        $tg->index_text($title, 2);