X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/3215b5a9821d69a2216c2cdf2b64cd3eb27f7370..421559b230a764f25db95b9b7fd7ce968d3d8471:/IkiWiki/Plugin/search.pm diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index 3ac435197..eedfa6924 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -9,7 +9,7 @@ use IkiWiki 2.00; sub import { #{{{ hook(type => "checkconfig", id => "search", call => \&checkconfig); hook(type => "pagetemplate", id => "search", call => \&pagetemplate); - hook(type => "sanitize", id => "search", call => \&index); + hook(type => "postscan", id => "search", call => \&index); hook(type => "delete", id => "search", call => \&delete); hook(type => "cgi", id => "search", call => \&cgi); } # }}} @@ -48,8 +48,6 @@ my $scrubber; my $stemmer; sub index (@) { #{{{ my %params=@_; - - return $params{content} if $IkiWiki::preprocessing{$params{destpage}}; setupfiles(); @@ -108,8 +106,14 @@ sub index (@) { #{{{ if (! $stemmer) { my $langcode=$ENV{LANG} || "en"; $langcode=~s/_.*//; - eval { $stemmer=Search::Xapian::Stem->new($langcode) }; - if ($@) { + + # 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"); } } @@ -119,15 +123,13 @@ sub index (@) { #{{{ $tg->index_text($caption, 2); $tg->index_text($title, 2) if $title ne $caption; $tg->index_text($toindex); - $tg->index_text(lc($title), 1, "ZS"); # for title:foo + $tg->index_text(lc($title), 1, "S"); # for title:foo foreach my $link (@{$links{$params{page}}}) { - $tg->index_text(lc($link), 1, "ZLINK"); # for link:bar + $tg->index_text(lc($link), 1, "XLINK"); # for link:bar } $doc->add_term($pageterm); $db->replace_document_by_term($pageterm, $doc); - - return $params{content}; } #}}} sub delete (@) { #{{{ @@ -188,15 +190,19 @@ sub xapiandb () { #{{{ return $db; } #}}} +{ +my $setup=0; sub setupfiles () { #{{{ - if (! -e $config{wikistatedir}."/xapian" || $config{rebuild}) { + if (! $setup and (! -e $config{wikistatedir}."/xapian" || $config{rebuild})) { writefile("omega.conf", $config{wikistatedir}."/xapian", "database_dir .\n". "template_dir ./templates\n"); writefile("query", $config{wikistatedir}."/xapian/templates", IkiWiki::misctemplate(gettext("search"), readfile(IkiWiki::template_file("searchquery.tmpl")))); + $setup=1; } } #}}} +} 1