+ $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
+ }
+
+ $doc->add_term($pageterm);
+ $db->replace_document_by_term($pageterm, $doc);
+}
+
+sub delete (@) {
+ my $db=xapiandb();
+ foreach my $page (@_) {
+ my $pageterm=pageterm(pagename($page));
+ $db->delete_document_by_term($pageterm) if defined $pageterm;
+ }
+}
+
+sub cgi ($) {
+ my $cgi=shift;
+
+ if (defined $cgi->param('P')) {
+ # only works for GET requests
+ chdir("$config{wikistatedir}/xapian") || error("chdir: $!");
+ $ENV{OMEGA_CONFIG_FILE}="./omega.conf";
+ $ENV{CGIURL}=$config{cgiurl},
+ IkiWiki::loadindex();
+ $ENV{HELPLINK}=htmllink("", "", "ikiwiki/searching",
+ noimageinline => 1, linktext => "Help");
+ exec($config{omega_cgi}) || error("$config{omega_cgi} failed: $!");
+ }
+}
+
+sub pageterm ($) {
+ my $page=shift;
+
+ # 240 is the number used by omindex to decide when to hash an
+ # overlong term. This does not use a compatible hash method though.
+ if (length $page > 240) {
+ eval q{use Digest::SHA};
+ if ($@) {
+ debug("search: ".sprintf(gettext("need Digest::SHA to index %s"), $page)) if $@;
+ return undef;