3 # Copyright 2012 BibLibre SARL
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 use Koha::SearchEngine::Index;
30 $|=1; # flushes output
32 if ( C4::Context->preference("SearchEngine") ne 'Solr' ) {
33 warn "System preference 'SearchEngine' not equal 'Solr'.";
34 warn "We can not indexing";
40 my ( $reset, $number, $recordtype, $biblionumbers, $optimize, $info, $want_help );
44 't:s' => \$recordtype,
45 'w:s' => \$biblionumbers,
48 'h|help' => \$want_help,
50 my $debug = C4::Context->preference("DebugLevel");
51 my $index_service = Koha::SearchEngine::Index->new;
52 my $solrurl = $index_service->searchengine->config->SolrAPI;
54 my $ping = &ping_command;
56 print "SolrAPI = $solrurl\n";
57 print "Solr is Down\n";
63 &print_help if ($want_help);
64 &print_info if ($info);
67 &reset_index("recordtype:".$recordtype);
73 if (defined $biblionumbers){
74 if (not defined $recordtype) { print "You must specify a recordtype\n"; exit 1;}
75 &index_biblio($_) for split ',', $biblionumbers;
76 } elsif (defined $recordtype) {
88 my ($biblionumber) = @_;
89 $index_service->index_record($recordtype, [ $biblionumber ] );
93 my $dbh = C4::Context->dbh;
94 $dbh->do('SET NAMES UTF8;');
97 if ( $recordtype eq 'biblio' ) {
98 $query = "SELECT biblionumber FROM biblio ORDER BY biblionumber";
99 } elsif ( $recordtype eq 'authority' ) {
100 $query = "SELECT authid FROM auth_header ORDER BY authid";
102 $query .= " LIMIT $number" if $number;
104 my $sth = $dbh->prepare( $query );
107 $index_service->index_record($recordtype, [ map { $_->[0] } @{ $sth->fetchall_arrayref } ] );
115 $debug eq '2' && &count_all_docs eq 0 && warn "Index cleaned!"
119 my $commiturl = "/update?stream.body=%3Ccommit/%3E";
120 my $urlreturns = get $solrurl.$commiturl;
124 my $pingurl = "/admin/ping";
125 my $urlreturns = get $solrurl.$pingurl;
130 my $deleteurl = "/update?stream.body=%3Cdelete%3E%3Cquery%3E".$query."%3C/query%3E%3C/delete%3E";
131 my $urlreturns = get $solrurl.$deleteurl;
135 $index_service->optimize;
139 my $queryurl = "/select/?q=*:*";
140 my $urlreturns = get $solrurl.$queryurl;
141 my $xmlsimple = XML::Simple->new();
142 my $data = $xmlsimple->XMLin($urlreturns);
143 return $data->{result}->{numFound};
147 my $count = &count_all_docs;
150 How many indexed documents = $count;
156 $0: reindex biblios and/or authorities in Solr.
158 Use this batch job to reindex all biblio or authority records in your Koha database. This job is useful only if you are using Solr search engine.
161 -t biblio index bibliographic records
163 -t authority index authority records
165 -r clear Solr index before adding records to index - use this option carefully!
167 -n 100 index 100 first records
169 -n "100,2" index 2 records after 100th (101 and 102)
171 -w 101 index biblio with biblionumber equals 101
173 -o launch optimize command at the end of indexing
175 -i gives solr install information: SolrAPI value and count all documents indexed
177 --help or -h show this message.