+ $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 (@) {
+ return if $config{google_search};
+
+ 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')) {
+ if ($config{google_search}) {
+ print $cgi->redirect("https://www.google.com/search?sitesearch=$config{url}&q=".$cgi->param('P'));
+ exit 0;
+ }
+ else {
+ # only works for GET requests
+ chdir("$config{wikistatedir}/xapian") || error("chdir: $!");
+ $ENV{OMEGA_CONFIG_FILE}="./omega.conf";
+ $ENV{CGIURL}=IkiWiki::cgiurl();
+ IkiWiki::loadindex();
+ $ENV{HELPLINK}=htmllink("", "", "ikiwiki/searching",
+ noimageinline => 1, linktext => "Help");
+ exec($config{omega_cgi}) || error("$config{omega_cgi} failed: $!");