2 # hyperestraier search engine plugin
3 package IkiWiki::Plugin::search;
10 IkiWiki::hook(type => "checkconfig", id => "hyperestraier",
11 call => \&checkconfig);
12 IkiWiki::hook(type => "delete", id => "hyperestraier",
14 IkiWiki::hook(type => "render", id => "hyperestraier",
16 IkiWiki::hook(type => "cgi", id => "hyperestraier",
20 sub checkconfig () { #{{{
21 foreach my $required (qw(url cgiurl)) {
22 if (! length $IkiWiki::config{$required}) {
23 IkiWiki::error("Must specify $required when using the search plugin\n");
27 $IkiWiki::config{headercontent}.=qq{
28 <form method="get" action="$IkiWiki::config{cgiurl}" id="searchform">
30 <input type="text" name="phrase" value="" size="16" />
31 <input type="hidden" name="enc" value="UTF-8" />
32 <input type="hidden" name="do" value="hyperestraier" />
39 IkiWiki::debug("cleaning hyperestraier search index");
40 IkiWiki::estcmd("purge -cl");
45 IkiWiki::debug("updating hyperestraier search index");
46 IkiWiki::estcmd("gather -cm -bc -cl -sd",
48 $IkiWiki::config{destdir}."/".$IkiWiki::renderedfiles{IkiWiki::pagename($_)}
57 if (defined $cgi->param('phrase')) {
58 # only works for GET requests
59 chdir("$IkiWiki::config{wikistatedir}/hyperestraier") || IkiWiki::error("chdir: $!");
60 exec("./".IkiWiki::basename($IkiWiki::config{cgiurl})) || IkiWiki::error("estseek.cgi failed");
64 # Easier to keep these in the IkiWiki namespace.
69 return if $configured;
72 my $estdir="$config{wikistatedir}/hyperestraier";
73 my $cgi=basename($config{cgiurl});
75 open(TEMPLATE, ">$estdir/$cgi.tmpl") ||
76 error("write $estdir/$cgi.tmpl: $!");
77 print TEMPLATE misctemplate("search",
78 "<!--ESTFORM-->\n\n<!--ESTRESULT-->\n\n<!--ESTINFO-->\n\n");
80 open(TEMPLATE, ">$estdir/$cgi.conf") ||
81 error("write $estdir/$cgi.conf: $!");
82 my $template=HTML::Template->new(
83 filename => "$config{templatedir}/estseek.conf"
85 eval q{use Cwd 'abs_path'};
88 tmplfile => "$estdir/$cgi.tmpl",
89 destdir => abs_path($config{destdir}),
92 print TEMPLATE $template->output;
94 $cgi="$estdir/".basename($config{cgiurl});
96 symlink("/usr/lib/estraier/estseek.cgi", $cgi) ||
97 error("symlink $cgi: $!");
100 sub estcmd ($;@) { #{{{
101 my @params=split(' ', shift);
102 push @params, "-cl", "$config{wikistatedir}/hyperestraier";
107 my $pid=open(CHILD, "|-");
113 close(CHILD) || error("estcmd @params exited nonzero: $?");
117 open(STDOUT, "/dev/null"); # shut it up (closing won't work)
118 exec("estcmd", @params) || error("can't run estcmd");