From a2101345cc68d34378406e5c944b51cfb1521016 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 22 Jul 2016 08:57:20 +0100 Subject: [PATCH] Bug 16588: Remove Readonly from SearchEngine Test plan: Make sure you are able to reindex and search for records at the OPAC using ElasticSearch --- C4/AuthoritiesMarc.pm | 4 ++-- C4/Biblio.pm | 4 ++-- C4/Items.pm | 2 +- C4/Matcher.pm | 2 +- C4/XISBN.pm | 2 +- Koha/ElasticSearch.pm | 7 ++++--- Koha/SearchEngine.pm | 7 ++++--- Koha/SearchEngine/QueryBuilder.pm | 2 +- acqui/neworderbiblio.pl | 4 ++-- authorities/authorities-home.pl | 4 ++-- authorities/authorities-list.pl | 2 +- catalogue/search.pl | 4 ++-- cataloguing/addbooks.pl | 4 ++-- cataloguing/value_builder/marc21_linking_section.pl | 2 +- cataloguing/value_builder/unimarc_field_4XX.pl | 2 +- circ/circulation.pl | 2 +- misc/migration_tools/bulkmarcimport.pl | 4 ++-- misc/search_tools/rebuild_elastic_search.pl | 4 ++-- opac/opac-authorities-home.pl | 4 ++-- serials/subscription-bib-search.pl | 2 +- 20 files changed, 35 insertions(+), 33 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index e14c85f..5c66960 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -353,7 +353,7 @@ sub CountUsage { $query= "an:".$authid; # 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 $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"; @@ -827,7 +827,7 @@ sub FindDuplicateAuthority { $_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/); } } - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::AUTHORITIES_INDEX}); + 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} ) { diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 2798325..2907d39 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2922,8 +2922,8 @@ sub ModZebra { my $indexer = Koha::ElasticSearch::Indexer->new( { index => $server eq 'biblioserver' - ? $Koha::SearchEngine::BIBLIOS_INDEX - : $Koha::SearchEngine::AUTHORITIES_INDEX + ? Koha::SearchEngine::BIBLIOS_INDEX + : Koha::SearchEngine::AUTHORITIES_INDEX } ); if ( $op eq 'specialUpdate' ) { diff --git a/C4/Items.pm b/C4/Items.pm index 81a8263..9a4a1ef 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2514,7 +2514,7 @@ sub GetAnalyticsCount { ### ZOOM search here my $query; $query= "hi=".$itemnumber; - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + 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 b51d10e..9dd3874 100644 --- a/C4/Matcher.pm +++ b/C4/Matcher.pm @@ -656,7 +656,7 @@ 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. } - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my $searcher = Koha::SearchEngine::Search->new({index => Koha::SearchEngine::BIBLIOS_INDEX}); ( $error, $searchresults, $total_hits ) = $searcher->simple_search_compat( $query, 0, $max_matches ); } diff --git a/C4/XISBN.pm b/C4/XISBN.pm index 5512633..008733b 100644 --- a/C4/XISBN.pm +++ b/C4/XISBN.pm @@ -66,7 +66,7 @@ sub _get_biblio_from_xisbn { my $xisbn = shift; my $dbh = C4::Context->dbh; - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + 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 ); diff --git a/Koha/ElasticSearch.pm b/Koha/ElasticSearch.pm index d56c344..1e42aff 100644 --- a/Koha/ElasticSearch.pm +++ b/Koha/ElasticSearch.pm @@ -26,7 +26,6 @@ use Koha::Database; use Carp; use JSON; use Modern::Perl; -use Readonly; use Data::Dumper; # TODO remove @@ -34,8 +33,10 @@ __PACKAGE__->mk_ro_accessors(qw( index )); __PACKAGE__->mk_accessors(qw( sort_fields )); # Constants to refer to the standard index names -Readonly our $BIBLIOS_INDEX => 'biblios'; -Readonly our $AUTHORITIES_INDEX => 'authorities'; +use constant { + BIBLIOS_INDEX => 'biblios', + AUTHORITIES_INDEX => 'authorities', +}; =head1 NAME diff --git a/Koha/SearchEngine.pm b/Koha/SearchEngine.pm index 70ef799..2a3c7e4 100644 --- a/Koha/SearchEngine.pm +++ b/Koha/SearchEngine.pm @@ -19,7 +19,6 @@ package Koha::SearchEngine; # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use Modern::Perl; -use Readonly; =head1 NAME @@ -42,5 +41,7 @@ indicate that you want to be working with the authorities index. # 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'; +use constant { + BIBLIOS_INDEX => 'biblios', + AUTHORITIES_INDEX => 'authorities', +}; diff --git a/Koha/SearchEngine/QueryBuilder.pm b/Koha/SearchEngine/QueryBuilder.pm index 62a6b2c..64e81fd 100644 --- a/Koha/SearchEngine/QueryBuilder.pm +++ b/Koha/SearchEngine/QueryBuilder.pm @@ -33,7 +33,7 @@ and just get whatever querybuilder you need. =head1 SYNOPSIS use Koha::SearchEngine::QueryBuilder; - my $qb = Koha::SearchEngine::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my $qb = Koha::SearchEngine::QueryBuilder->new({index => Koha::SearchEngine::BIBLIOS_INDEX}); =head1 METHODS diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index 01fb1e2..28592a5 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -102,8 +102,8 @@ my @operands = $query; my $QParser; $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser')); my $builtquery; -my $builder = Koha::SearchEngine::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); -my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); +my $builder = Koha::SearchEngine::QueryBuilder->new({index => Koha::SearchEngine::BIBLIOS_INDEX}); +my $searcher = Koha::SearchEngine::Search->new({index => Koha::SearchEngine::BIBLIOS_INDEX}); if ($QParser) { $builtquery = $query; } else { diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 426b1ba..a6f1bab 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -80,9 +80,9 @@ if ( $op eq "do_search" ) { my $resultsperpage = $query->param('resultsperpage') || 20; my $builder = Koha::SearchEngine::QueryBuilder->new( - { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); + { index => Koha::SearchEngine::AUTHORITIES_INDEX } ); my $searcher = Koha::SearchEngine::Search->new( - { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); + { index => Koha::SearchEngine::AUTHORITIES_INDEX } ); my $search_query = $builder->build_authorities_query_compat( [$marclist], [$and_or], [$excluding], [$operator], [$value], $authtypecode, $orderby diff --git a/authorities/authorities-list.pl b/authorities/authorities-list.pl index 0afa5e7..c361c78 100755 --- a/authorities/authorities-list.pl +++ b/authorities/authorities-list.pl @@ -26,7 +26,7 @@ foreach my $authority (@$dataauthorities){ my $query; $query= "an=".$authority->{'authid'}; # search for biblios mapped - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + 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/catalogue/search.pl b/catalogue/search.pl index dcbd21c..4db7d0c 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -476,9 +476,9 @@ my $expanded_facet = $params->{'expand'}; my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type); my $builder = Koha::SearchEngine::QueryBuilder->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + { index => Koha::SearchEngine::BIBLIOS_INDEX } ); my $searcher = Koha::SearchEngine::Search->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + { index => Koha::SearchEngine::BIBLIOS_INDEX } ); ## I. BUILD THE QUERY ( diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl index 672a070..035ff96 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -78,9 +78,9 @@ if ($query) { $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser')); my $builtquery; my $builder = Koha::SearchEngine::QueryBuilder->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + { index => Koha::SearchEngine::BIBLIOS_INDEX } ); my $searcher = Koha::SearchEngine::Search->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + { index => Koha::SearchEngine::BIBLIOS_INDEX } ); if ($QParser) { $builtquery = $query; } else { diff --git a/cataloguing/value_builder/marc21_linking_section.pl b/cataloguing/value_builder/marc21_linking_section.pl index 448a609..a037e7a 100755 --- a/cataloguing/value_builder/marc21_linking_section.pl +++ b/cataloguing/value_builder/marc21_linking_section.pl @@ -183,7 +183,7 @@ my $launcher = sub { $op = 'and'; } my $searcher = Koha::SearchEngine::Search->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + { index => Koha::SearchEngine::BIBLIOS_INDEX } ); $search = 'kw:' . $search . " $op mc-itemtype:" . $itype if $itype; my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $search, diff --git a/cataloguing/value_builder/unimarc_field_4XX.pl b/cataloguing/value_builder/unimarc_field_4XX.pl index a5f2103..36f467d 100755 --- a/cataloguing/value_builder/unimarc_field_4XX.pl +++ b/cataloguing/value_builder/unimarc_field_4XX.pl @@ -369,7 +369,7 @@ sub plugin { $op = 'and'; } $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype; - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + 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 ed00e2d..05374d6 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -348,7 +348,7 @@ if (@$barcodes) { { $template_params->{FALLBACK} = 1; - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my $searcher = Koha::SearchEngine::Search->new({index => Koha::SearchEngine::BIBLIOS_INDEX}); my $query = "kw=" . $barcode; my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat($query, 0, 10); diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index d007d29..02d87d6 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -223,8 +223,8 @@ my $searcher = Koha::SearchEngine::Search->new( { index => ( $authorities - ? $Koha::SearchEngine::AUTHORITIES_INDEX - : $Koha::SearchEngine::BIBLIOS_INDEX + ? Koha::SearchEngine::AUTHORITIES_INDEX + : Koha::SearchEngine::BIBLIOS_INDEX ) } ); diff --git a/misc/search_tools/rebuild_elastic_search.pl b/misc/search_tools/rebuild_elastic_search.pl index 66d0cbb..6292351 100755 --- a/misc/search_tools/rebuild_elastic_search.pl +++ b/misc/search_tools/rebuild_elastic_search.pl @@ -136,7 +136,7 @@ if ($index_biblios) { $records->next(); } } - do_reindex($next, $Koha::ElasticSearch::BIBLIOS_INDEX); + do_reindex($next, Koha::ElasticSearch::BIBLIOS_INDEX); } if ($index_authorities) { _log(1, "Indexing authorities\n"); @@ -153,7 +153,7 @@ if ($index_authorities) { $records->next(); } } - do_reindex($next, $Koha::ElasticSearch::AUTHORITIES_INDEX); + do_reindex($next, Koha::ElasticSearch::AUTHORITIES_INDEX); } sub do_reindex { diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index 5b1a42b..85f82de 100755 --- a/opac/opac-authorities-home.pl +++ b/opac/opac-authorities-home.pl @@ -59,9 +59,9 @@ if ( $op eq "do_search" ) { my @tags; my $builder = Koha::SearchEngine::QueryBuilder->new( - { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); + { index => Koha::SearchEngine::AUTHORITIES_INDEX } ); my $searcher = Koha::SearchEngine::Search->new( - { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); + { index => Koha::SearchEngine::AUTHORITIES_INDEX } ); my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or, \@excluding, \@operator, \@value, $authtypecode, $orderby ); my ( $results, $total ) = diff --git a/serials/subscription-bib-search.pl b/serials/subscription-bib-search.pl index 8e44603..6e425a5 100755 --- a/serials/subscription-bib-search.pl +++ b/serials/subscription-bib-search.pl @@ -99,7 +99,7 @@ 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 $searcher = Koha::SearchEngine::Search->new({index => Koha::SearchEngine::BIBLIOS_INDEX}); my ( $error, $marcrecords, $total_hits ) = $searcher->simple_search_compat( $query, $startfrom * $resultsperpage, $resultsperpage ); my $total = 0; -- 2.8.1