- $sample=~s/\n/ /g;
-
- # data used by omega
- $doc->set_data(
- "url=".urlto($params{page}, "")."\n".
- "sample=$sample\n".
- "caption=$title\n".
- "modtime=$IkiWiki::pagemtime{$params{page}}\n".
- "size=".length($params{content})."\n"
- );
-
- my $tg = Search::Xapian::TermGenerator->new();
- $tg->set_stemmer(new Search::Xapian::Stem("english"));
- $tg->set_document($doc);
- $tg->index_text($params{page}, 2);
- $tg->index_text($title, 2);
- $tg->index_text($toindex);
-
- my $pageterm=pageterm($params{page});
- $doc->add_term($pageterm);
- $db->replace_document_by_term($pageterm, $doc);
+ }
+ $sample=~s/\n/ /g;
+
+ # data used by omega
+ # Decode html entities in it, since omega re-encodes them.
+ eval q{use HTML::Entities};
+ $doc->set_data(
+ "url=".urlto($params{page}, "")."\n".
+ "sample=".decode_entities($sample)."\n".
+ "caption=".decode_entities($caption)."\n".
+ "modtime=$IkiWiki::pagemtime{$params{page}}\n".
+ "size=".length($params{content})."\n"
+ );
+
+ # Index document and add terms for other metadata.
+ my $tg = Search::Xapian::TermGenerator->new();
+ if (! $stemmer) {
+ my $langcode=$ENV{LANG} || "en";
+ $langcode=~s/_.*//;
+
+ # This whitelist is here to work around a xapian bug (#486138)
+ my @whitelist=qw{da de en es fi fr hu it no pt ru ro sv tr};
+
+ if (grep { $_ eq $langcode } @whitelist) {
+ $stemmer=Search::Xapian::Stem->new($langcode);
+ }
+ else {
+ $stemmer=Search::Xapian::Stem->new("english");
+ }
+ }
+ $tg->set_stemmer($stemmer);
+ $tg->set_document($doc);
+ $tg->index_text($params{page}, 2);
+ $tg->index_text($caption, 2);
+ $tg->index_text($title, 2) if $title ne $caption;
+ $tg->index_text($toindex);
+ $tg->index_text(lc($title), 1, "S"); # for title:foo
+ foreach my $link (@{$links{$params{page}}}) {
+ $tg->index_text(lc($link), 1, "XLINK"); # for link:bar