From 24c16f739e3f7099a8e356472fc1b63e01feb908 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 Signed-off-by: Nick Clemens --- C4/Biblio.pm | 4 ++-- C4/Items.pm | 2 +- C4/Matcher.pm | 2 +- C4/XISBN.pm | 2 +- Koha/SearchEngine.pm | 7 ++++--- Koha/SearchEngine/Elasticsearch.pm | 7 ++++--- Koha/SearchEngine/QueryBuilder.pm | 2 +- acqui/neworderbiblio.pl | 4 ++-- authorities/authorities-home.pl | 4 ++-- 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 +- 18 files changed, 32 insertions(+), 30 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 91707fd..c64b62c 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2683,8 +2683,8 @@ sub ModZebra { my $indexer = Koha::SearchEngine::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 a3ecd87..3b82df5 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2263,7 +2263,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 7209511..7ec931b 100644 --- a/C4/Matcher.pm +++ b/C4/Matcher.pm @@ -664,7 +664,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, undef, skip_normalize => 1 ); diff --git a/C4/XISBN.pm b/C4/XISBN.pm index 884d772..a48447f 100644 --- a/C4/XISBN.pm +++ b/C4/XISBN.pm @@ -56,7 +56,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/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/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index d859a39..1efe5a9 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -29,7 +29,6 @@ use Koha::SearchMarcMaps; use Carp; use JSON; use Modern::Perl; -use Readonly; use Search::Elasticsearch; use Try::Tiny; use YAML::Syck; @@ -40,8 +39,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/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 f083398..5d88431 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -101,8 +101,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 89142f2..c991af8 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -87,9 +87,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/catalogue/search.pl b/catalogue/search.pl index 79ba83f..323457a 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -456,9 +456,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 ae4d7ac..8e50202 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -68,9 +68,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 0fb9b7b..60d2373 100755 --- a/cataloguing/value_builder/marc21_linking_section.pl +++ b/cataloguing/value_builder/marc21_linking_section.pl @@ -182,7 +182,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 c514349..27329be 100755 --- a/cataloguing/value_builder/unimarc_field_4XX.pl +++ b/cataloguing/value_builder/unimarc_field_4XX.pl @@ -368,7 +368,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 1617584..c6d9d03 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -365,7 +365,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 7a5a581..806f5f1 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -251,8 +251,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 6faa32c..bec107d 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::SearchEngine::Elasticsearch::BIBLIOS_INDEX); + do_reindex($next, Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX); } if ($index_authorities) { _log(1, "Indexing authorities\n"); @@ -153,7 +153,7 @@ if ($index_authorities) { $records->next(); } } - do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); + do_reindex($next, Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); } sub do_reindex { diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index 4dcb33c..c1ba8ba 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 $offset = ( $startfrom - 1 ) * $resultsperpage + 1; diff --git a/serials/subscription-bib-search.pl b/serials/subscription-bib-search.pl index 88de874..17223cb 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.1.4