3 # This script will build an index of all the biblios in a koha database
4 # Its using english stemming at the moment. But that can be changed and is only
5 # indexing author and title
7 # Combine this with the search.cgi script to search Koha using Plucene
8 # This is still a work in progress, use with caution
12 # Copyright 2005 Katipo Communications
14 # This file is part of Koha.
16 # Koha is free software; you can redistribute it and/or modify it under the
17 # terms of the GNU General Public License as published by the Free Software
18 # Foundation; either version 2 of the License, or (at your option) any later
21 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
22 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
23 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License along with
26 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
27 # Suite 330, Boston, MA 02111-1307 USA
29 use lib '/usr/local/koha/intranet/modules';
32 use Plucene::Index::Writer;
33 use Plucene::Plugin::Analyzer::PorterAnalyzer;
34 use Plucene::Document;
36 # connect to the database and fetch all the biblios
37 my $dbh = C4::Context->dbh();
39 my $query = "SELECT * FROM biblio";
40 my $sth = $dbh->prepare($query);
44 # create an index writer
45 # currently it makes the index in /tmp/plucene
46 # PLEASE change this if you want to use the script in production
47 my $writer = Plucene::Index::Writer->new(
49 Plucene::Plugin::Analyzer::PorterAnalyzer->new(),
50 1 # Create the index from scratch
53 # For each biblio, add its information to the index
55 while ( my $data = $sth->fetchrow_hashref() ) {
56 my $doc = Plucene::Document->new();
58 Plucene::Document::Field->Keyword( filename => $data->{biblionumber} )
60 $doc->add( Plucene::Document::Field->Text( title => $data->{'title'} ) );
61 $doc->add( Plucene::Document::Field->Text( author => $data->{'author'} ) );
62 $writer->add_document($doc);