3 # script to search the plucene index of the database
4 # most of this will be shifted to a module when it moves out of the proof of concept stage
8 # Copyright 2005 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 use Plucene::Search::IndexSearcher;
27 use Plucene::Plugin::Analyzer::PorterAnalyzer;
28 use Plucene::QueryParser;
29 use Plucene::Search::HitCollector;
32 use C4::Interface::CGI::Output;
39 # get a template, opac-pluceneresults.tmpl is currently an exact copy of
40 # opac-searchresults.tmpl so just make a copy.
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43 template_name => "opac-pluceneresults.tmpl",
50 # the script expects an input called query;
51 my $query = $cgi->param('query');
53 # tell the script what index to use (change this to match whatever is in indexer.pl)
54 my $searcher = Plucene::Search::IndexSearcher->new("/tmp/plucene/");
56 # the important bit here is default=>"title"
57 # that says if we dont specify what to search, search the title field
58 my $parser = Plucene::QueryParser->new(
60 analyzer => Plucene::Plugin::Analyzer::PorterAnalyzer->new(),
65 my $parsed = $parser->parse($query);
69 # build an array of results,
70 # we could use the $score to rank them, but its currently not doing that
71 my $hc = Plucene::Search::HitCollector->new(
73 my ( $self, $doc, $score ) = @_;
74 my $res = eval { $searcher->doc($doc) };
75 push @docs, $res if $res;
80 $searcher->search_hc( $parsed, $hc );
82 # map the results into a format our template is expecting
85 biblionumber => $_->get("filename")->string,
86 title => $_->get("title")->string,
87 author => $_->get("author")->string,
91 # pass the results to the template
92 my $num_records = @results;
94 search_results => \@results,
95 numrecords => $num_records,
98 output_html_with_http_headers $cgi, $cookie, $template->output;