From b4392018bc1f9bf6a2f7dfe70b488856ad3a3897 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Wed, 8 Jul 2015 16:34:12 +1200 Subject: [PATCH] Bug 12478: make things using SimpleSearch use the new version Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- C4/AuthoritiesMarc.pm | 11 ++++- C4/Items.pm | 6 ++- C4/Matcher.pm | 8 ++-- C4/XISBN.pm | 6 ++- Koha/ElasticSearch/Indexer.pm | 1 + Koha/SearchEngine.pm | 46 +++++++++++++++++++ Koha/SearchEngine/Elasticsearch/Search.pm | 7 +-- acqui/neworderbiblio.pl | 10 ++-- authorities/authorities-list.pl | 5 +- .../value_builder/marc21_linking_section.pl | 10 +++- .../value_builder/unimarc_field_4XX.pl | 11 ++++- circ/circulation.pl | 5 +- .../data/mysql/elasticsearch_mapping.sql | 8 ++-- labels/label-item-search.pl | 9 ++-- misc/migration_tools/bulkmarcimport.pl | 16 ++++++- .../migration_tools/checkNonIndexedBiblios.pl | 10 ++-- .../remove_unused_authorities.pl | 5 +- serials/subscription-bib-search.pl | 6 ++- 18 files changed, 147 insertions(+), 33 deletions(-) create mode 100644 Koha/SearchEngine.pm diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 82c53b478a..dcfc4d1944 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -29,6 +29,9 @@ use C4::Log; use Koha::MetadataRecord::Authority; use Koha::Authorities; use Koha::Authority::Types; +use Koha::Authority; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; use vars qw(@ISA @EXPORT); @@ -349,7 +352,10 @@ sub CountUsage { ### ZOOM search here my $query; $query= "an:".$authid; - my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10); + # Should really be replaced with a real count call, this is a + # bad way. + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my ($err,$res,$result) = $searcher->simple_search_compat($query,0,1); if ($err) { warn "Error: $err from search $query"; $result = 0; @@ -822,7 +828,8 @@ sub FindDuplicateAuthority { $_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/); } } - my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] ); + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::AUTHORITIES_INDEX}); + my ($error, $results, $total_hits) = $searcher->simple_search_compat( $query, 0, 1 ); # there is at least 1 result => return the 1st one if (!defined $error && @{$results} ) { my $marcrecord = C4::Search::new_record_from_zebra( diff --git a/C4/Items.pm b/C4/Items.pm index 7f9a3da35c..c4f239b06e 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -38,6 +38,8 @@ use Koha::DateUtils qw/dt_from_string/; use Koha::Database; use Koha::Database; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; use vars qw(@ISA @EXPORT); @@ -2601,12 +2603,12 @@ counts Usage of itemnumber in Analytical bibliorecords. sub GetAnalyticsCount { my ($itemnumber) = @_; - require C4::Search; ### ZOOM search here my $query; $query= "hi=".$itemnumber; - my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10); + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my ($err,$res,$result) = $searcher->simple_search_compat($query,0,10); return ($result); } diff --git a/C4/Matcher.pm b/C4/Matcher.pm index 7d91cf29ea..b51d10e859 100644 --- a/C4/Matcher.pm +++ b/C4/Matcher.pm @@ -23,7 +23,8 @@ use warnings; use C4::Context; use MARC::Record; - +use Koha::SearchEngine; +use Koha::SearchEngine::Search; =head1 NAME @@ -655,10 +656,9 @@ sub get_matches { #NOTE: double-quote the values so you don't get a "Embedded truncation not supported" error when a term has a ? in it. } - require C4::Search; - + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); ( $error, $searchresults, $total_hits ) = - C4::Search::SimpleSearch( $query, 0, $max_matches ); + $searcher->simple_search_compat( $query, 0, $max_matches ); } elsif ( $self->{'record_type'} eq 'authority' ) { my $authresults; diff --git a/C4/XISBN.pm b/C4/XISBN.pm index df313563ee..55126334b3 100644 --- a/C4/XISBN.pm +++ b/C4/XISBN.pm @@ -26,6 +26,9 @@ use C4::External::Syndetics qw(get_syndetics_editions); use LWP::UserAgent; use HTTP::Request::Common; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; + use strict; #use warnings; FIXME - Bug 2505 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -63,7 +66,8 @@ sub _get_biblio_from_xisbn { my $xisbn = shift; my $dbh = C4::Context->dbh; - my ( $errors, $results, $total_hits ) = C4::Search::SimpleSearch( "nb=$xisbn", 0, 1 ); + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( "nb=$xisbn", 0, 1 ); return unless ( !$errors && scalar @$results ); my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[0] ); diff --git a/Koha/ElasticSearch/Indexer.pm b/Koha/ElasticSearch/Indexer.pm index a8e8280413..cc450dc5fc 100644 --- a/Koha/ElasticSearch/Indexer.pm +++ b/Koha/ElasticSearch/Indexer.pm @@ -96,6 +96,7 @@ it to be updated by a regular index cron job in the future. =cut sub update_index_background { + my $self = shift; $self->update_index(@_); } diff --git a/Koha/SearchEngine.pm b/Koha/SearchEngine.pm new file mode 100644 index 0000000000..70ef7997d5 --- /dev/null +++ b/Koha/SearchEngine.pm @@ -0,0 +1,46 @@ +package Koha::SearchEngine; +# This handles generic search-engine related functions + +# Copyright 2015 Catalyst IT +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Readonly; + +=head1 NAME + +Koha::SearchEngine - non-engine-specific data and functions + +=head1 VARIABLES / CONSTANTS + +=head2 BIBLIOS_INDEX + +Use this constant when creating a new L instance +to indicate that you want to be working with the biblio index. + +=head2 AUTHORITIES_INDEX + +Use this constant when creating a new L instance to +indicate that you want to be working with the authorities index. + +=cut + +# Search engine implementations should compare against these to determine +# what bit of storage is being requested. They will be sensible strings so +# may be used for, e.g., directory names. +Readonly our $BIBLIOS_INDEX => 'biblios'; +Readonly our $AUTHORITIES_INDEX => 'authorities'; diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 4218544023..07380207ce 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -38,6 +38,7 @@ Koha::SearchEngine::ElasticSearch::Search - search functions for Elasticsearch use base qw(Koha::ElasticSearch); use Koha::ItemTypes; +use Koha::SearchEngine::QueryBuilder; use Catmandu::Store::ElasticSearch; @@ -276,7 +277,7 @@ How many results to skip from the start of the results. =item C<$max_results> -The max number of results to return. The default is 1,000 (because unlimited +The max number of results to return. The default is 100 (because unlimited is a pretty terrible thing to do.) =back @@ -313,9 +314,9 @@ sub simple_search_compat { $max_results //= 100; unless (ref $query) { - # We'll push it through the query builder + # We'll push it through the query builder to sanitise everything. my $qb = Koha::SearchEngine::QueryBuilder->new(); - $query = $qb->build_query($query); + (undef,$query) = $qb->build_query_compat(undef, [$query]); } my $results = $self->search($query, undef, $max_results, %options); my @records; diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index 4bd0827ba0..9341fb5bd4 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -68,6 +68,9 @@ use C4::Members qw/ GetMember /; use C4::Budgets qw/ GetBudgetHierarchy /; use Koha::Acquisition::Bookseller; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; +use Koha::SearchEngine::QueryBuilder; my $input = new CGI; @@ -99,13 +102,14 @@ my @operands = $query; my $QParser; $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser')); my $builtquery; +my $builder = Koha::SearchEngine::QueryBuilder->new(); +my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); if ($QParser) { $builtquery = $query; } else { - my ( $builterror,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type); - ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(undef,\@operands); + ( undef,$builtquery,undef,undef,undef,undef,undef,undef,undef,undef) = $builder->build_query_compat(undef,\@operands); } -my ( $error, $marcresults, $total_hits ) = SimpleSearch( $builtquery, $results_per_page * ( $page - 1 ), $results_per_page ); +my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page); if (defined $error) { $template->param( diff --git a/authorities/authorities-list.pl b/authorities/authorities-list.pl index 2b15856dcf..0afa5e7fba 100755 --- a/authorities/authorities-list.pl +++ b/authorities/authorities-list.pl @@ -5,6 +5,8 @@ use C4::Context; use C4::AuthoritiesMarc; use utf8; use open qw[ :std :encoding(utf8) ]; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; my $dbh=C4::Context->dbh; my $datatypes_query = $dbh->prepare(<{'authid'}; # search for biblios mapped - my ($err,$res,$used) = C4::Search::SimpleSearch($query,0,10); + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my ($err,undef,$used) = $searcher->simple_search_compat($query,0,1); if (defined $err) { $used = 0; } diff --git a/cataloguing/value_builder/marc21_linking_section.pl b/cataloguing/value_builder/marc21_linking_section.pl index 61e21c7cc9..33b7420ecf 100755 --- a/cataloguing/value_builder/marc21_linking_section.pl +++ b/cataloguing/value_builder/marc21_linking_section.pl @@ -35,6 +35,9 @@ use C4::Branch; use Koha::ItemTypes; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; + my $builder = sub { my ( $params ) = @_; my $function_name = $params->{id}; @@ -179,8 +182,13 @@ my $launcher = sub { } else { $op = 'and'; } + my $searcher = Koha::SearchEngine::Search->new( + { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); $search = 'kw:' . $search . " $op mc-itemtype:" . $itype if $itype; - my ( $errors, $results, $total_hits ) = SimpleSearch( $search, $startfrom * $resultsperpage, $resultsperpage ); + my ( $errors, $results, $total_hits ) = + $searcher->simple_search_compat( $search, + $startfrom * $resultsperpage, + $resultsperpage ); if ( defined $errors ) { $results = []; } diff --git a/cataloguing/value_builder/unimarc_field_4XX.pl b/cataloguing/value_builder/unimarc_field_4XX.pl index f14a616a85..be299eb4a9 100755 --- a/cataloguing/value_builder/unimarc_field_4XX.pl +++ b/cataloguing/value_builder/unimarc_field_4XX.pl @@ -35,6 +35,14 @@ use C4::Branch; # GetBranches use Koha::ItemTypes; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; + +sub plugin_parameters { + my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_; + return ""; +} + sub plugin_javascript { my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_; my $function_name = $field_number; @@ -361,7 +369,8 @@ sub plugin { $op = 'and'; } $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype; - my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom * $resultsperpage, $resultsperpage ); + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat($search, $startfrom * $resultsperpage, $resultsperpage ); if (defined $errors ) { $results = []; } diff --git a/circ/circulation.pl b/circ/circulation.pl index 3a57685e93..7cf295f964 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -49,6 +49,8 @@ use Koha::DateUtils; use Koha::Database; use Koha::Patron::Messages; use Koha::Patron::Images; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; use Date::Calc qw( Today @@ -353,8 +355,9 @@ if (@$barcodes) { { $template_params->{FALLBACK} = 1; + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); my $query = "kw=" . $barcode; - my ( $searcherror, $results, $total_hits ) = SimpleSearch($query); + my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat($query, 0, 10); # if multiple hits, offer options to librarian if ( $total_hits > 0 ) { diff --git a/installer/data/mysql/elasticsearch_mapping.sql b/installer/data/mysql/elasticsearch_mapping.sql index 1bb7da68a6..92717ee4da 100644 --- a/installer/data/mysql/elasticsearch_mapping.sql +++ b/installer/data/mysql/elasticsearch_mapping.sql @@ -53,7 +53,7 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','rtype',FALSE,'','leader_/6',NULL,'leader_/6'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','bib-level',FALSE,'','leader_/7',NULL,'leader_/7'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','control-number',FALSE,'','001',NULL,'001'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string',NULL,'001',NULL); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','Local-number',FALSE,'string',NULL,'001',NULL); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','date-time-last-modified',FALSE,'','005','099d',NULL); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','microform-generation',FALSE,'','007_/11',NULL,'007_/11'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','material-type',FALSE,'','007','','007'); @@ -170,8 +170,8 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','subject',TRUE,'string','653a','610','653'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-classification',FALSE,'','952o','995k','952o'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-classification',FALSE,'',NULL,'686',NULL); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string','999c','001','999c'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string',NULL,'0909',NULL); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','Local-number',FALSE,'string','999c','001','999c'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','Local-number',FALSE,'string',NULL,'0909',NULL); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','itype',TRUE,'string','942c','200b','942c'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','itype',TRUE,'string','952y','995r','952y'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','acqdate',FALSE,'date','952d','9955','952d'); @@ -230,7 +230,7 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','an',FALSE,'number',NULL,'6219',NULL); -- Authorities: incomplete -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','local-number',FALSE,'string','001',NULL,'001'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Local-number',FALSE,'string','001',NULL,'001'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','authtype',FALSE,'','942a',NULL,'942a'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Kind-of-record',FALSE,'','008_/9',NULL,'008_/9'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Descriptive-cataloging-rules',FALSE,'','008_/10',NULL,'008_/10'); diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index c2d218a262..2ef5e157ca 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -29,6 +29,7 @@ use C4::Auth qw(get_template_and_user); use C4::Output qw(output_html_with_http_headers); use C4::Context; use C4::Search qw(SimpleSearch); +use C4::Dates; use C4::Biblio qw(TransformMarcToKoha); use C4::Items qw(GetItemInfosOf get_itemnumbers_of); use C4::Koha qw(GetItemTypes); @@ -36,6 +37,8 @@ use C4::Creators::Lib qw(html_table); use C4::Debug; use Koha::DateUtils; +use Koha::SearchEngine::Search; + BEGIN { $debug = $debug || $cgi_debug; if ($debug) { @@ -107,14 +110,14 @@ if ( $op eq "do_search" ) { } my $offset = $startfrom > 1 ? $startfrom - 1 : 0; - ( $error, $marcresults, $total_hits ) = - SimpleSearch( $ccl_query, $offset, $resultsperpage ); + my $searcher = Koha::SearchEngine::Search->new({index => 'biblios'}); + ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($ccl_query, $offset, $resultsperpage); if (!defined $error && @{$marcresults} ) { $show_results = @{$marcresults}; } else { - $debug and warn "ERROR label-item-search: no results from SimpleSearch"; + $debug and warn "ERROR label-item-search: no results from simple_search_compat"; # leave $show_results undef } diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index fc68e40138..d007d298ad 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -31,6 +31,9 @@ use Getopt::Long; use IO::File; use Pod::Usage; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; + use open qw( :std :encoding(UTF-8) ); binmode( STDOUT, ":encoding(UTF-8)" ); my ( $input_marc_file, $number, $offset) = ('',0,0); @@ -215,6 +218,17 @@ if ($logfile){ $loghandle= IO::File->new($logfile, $writemode) ; print $loghandle "id;operation;status\n"; } + +my $searcher = Koha::SearchEngine::Search->new( + { + index => ( + $authorities + ? $Koha::SearchEngine::AUTHORITIES_INDEX + : $Koha::SearchEngine::BIBLIOS_INDEX + ) + } +); + RECORD: while ( ) { my $record; # get records @@ -268,7 +282,7 @@ RECORD: while ( ) { my $query = build_query( $match, $record ); my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); $debug && warn $query; - my ( $error, $results, $totalhits ) = C4::Search::SimpleSearch( $query, 0, 3, [$server] ); + my ( $error, $results, $totalhits ) = $searcher->simple_search_compat( $query, 0, 3, [$server] ); # changed to warn so able to continue with one broken record if ( defined $error ) { warn "unable to search the database for duplicates : $error"; diff --git a/misc/migration_tools/checkNonIndexedBiblios.pl b/misc/migration_tools/checkNonIndexedBiblios.pl index 4d58a1304e..bd47431f0a 100755 --- a/misc/migration_tools/checkNonIndexedBiblios.pl +++ b/misc/migration_tools/checkNonIndexedBiblios.pl @@ -34,9 +34,10 @@ BEGIN { # Koha modules used use MARC::Record; use C4::Context; -use C4::Search; use Getopt::Long; +use Koha::SearchEngine::Search; + my ( $help, $confirm, $zebraqueue, $silent,$stealth ); GetOptions( @@ -62,13 +63,14 @@ $| = 1; my $sth = $dbh->prepare("SELECT biblionumber FROM biblio"); my $sth_insert = $dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,operation,server,done) VALUES (?,'specialUpdate','biblioserver',0)"); +my $searcher = Koha::SearchEngine::Search->new({index => 'biblios'}); + # We get all biblios $sth->execute; my ($nbhits); - # We check for each biblio while ( my ($biblionumber) = $sth->fetchrow ) { - (undef,undef,$nbhits) = SimpleSearch("Local-number=$biblionumber"); + (undef,undef,$nbhits) = $searcher->simple_search_compat("Local-number=$biblionumber"); print "biblionumber $biblionumber not indexed\n" unless $nbhits || $stealth; # If -z option we put the biblio in zebraqueue if ($zebraqueue && !$nbhits){ @@ -105,4 +107,4 @@ Syntax: \t./batchCheckNonIndexedBiblios.pl -s (s like silent => don't throws a warn every 1000 biblios to show progress) \t./batchCheckNonIndexedBiblios.pl -st (s like stealth => don't throws a warn every 1000 biblios to show progress and no warn for the non indexed biblionumbers, just the total) _USAGE_ -} \ No newline at end of file +} diff --git a/misc/migration_tools/remove_unused_authorities.pl b/misc/migration_tools/remove_unused_authorities.pl index eec2155d32..49bd1df90f 100755 --- a/misc/migration_tools/remove_unused_authorities.pl +++ b/misc/migration_tools/remove_unused_authorities.pl @@ -27,6 +27,8 @@ use C4::Context; use C4::AuthoritiesMarc; use Getopt::Long; +use Koha::SearchEngine::Search; + my @authtypes; my $want_help = 0; my $test = 0; @@ -66,11 +68,12 @@ $rqselect->execute; my $counter=0; my $totdeleted=0; my $totundeleted=0; +my $searcher = Koha::SearchEngine::Search->new({index => 'biblios'}); while (my $data=$rqselect->fetchrow_hashref){ my $query; $query= "an=".$data->{'authid'}; # search for biblios mapped - my ($err,$res,$used) = C4::Search::SimpleSearch($query,0,10); + my ($err,$res,$used) = $searcher->simple_search_compat($query,0,10); if (defined $err) { warn "error: $err on search $query\n"; next; diff --git a/serials/subscription-bib-search.pl b/serials/subscription-bib-search.pl index 09530ca414..8e44603e73 100755 --- a/serials/subscription-bib-search.pl +++ b/serials/subscription-bib-search.pl @@ -58,6 +58,9 @@ use C4::Search; use C4::Biblio; use C4::Debug; +use Koha::SearchEngine; +use Koha::SearchEngine::Search; + my $input = new CGI; my $op = $input->param('op') || q{}; my $dbh = C4::Context->dbh; @@ -96,8 +99,9 @@ if ( $op eq "do_search" && $query ) { $resultsperpage = $input->param('resultsperpage'); $resultsperpage = 20 if ( !defined $resultsperpage ); + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); my ( $error, $marcrecords, $total_hits ) = - SimpleSearch( $query, $startfrom * $resultsperpage, $resultsperpage ); + $searcher->simple_search_compat( $query, $startfrom * $resultsperpage, $resultsperpage ); my $total = 0; if ( defined $marcrecords ) { $total = scalar @{$marcrecords}; -- 2.39.5