From 5552d7ba4e838edc30ec45ac6a4fa22913ffe624 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Sep 2016 10:31:11 +0100 Subject: [PATCH] Bug 17372: Standardize Elasticsearch paths What we currently have: Koha/ElasticSearch.pm Koha/ElasticSearch/Indexer.pm Koha/SearchEngine/Elasticsearch/QueryBuilder.pm Koha/SearchEngine/Elasticsearch/Search.pm What we want: Koha/SearchEngine/Elasticsearch.pm Koha/SearchEngine/Elasticsearch/Indexer.pm Koha/SearchEngine/Elasticsearch/QueryBuilder.pm Koha/SearchEngine/Elasticsearch/Search.pm Test plan: % git grep -i Koha::ElasticSearch % git grep ElasticSearch|grep -v Catmandu::Store::ElasticSearch should not return any result Do a full reindex and search for records Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall --- C4/Biblio.pm | 4 ++-- Koha/{ElasticSearch.pm => SearchEngine/Elasticsearch.pm} | 6 ++++-- Koha/{ElasticSearch => SearchEngine/Elasticsearch}/Indexer.pm | 10 +++++----- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 4 ++-- Koha/SearchEngine/Elasticsearch/Search.pm | 6 +++--- installer/data/mysql/updatedatabase.pl | 4 ++-- installer/install.pl | 4 ++-- misc/search_tools/rebuild_elastic_search.pl | 8 ++++---- t/00-load.t | 2 +- t/db_dependent/{Koha_ElasticSearch.t => Koha_Elasticsearch.} | 2 +- ...ha_ElasticSearch_Indexer.t => Koha_Elasticsearch_Indexer.t} | 4 ++-- t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t | 2 +- 12 files changed, 29 insertions(+), 27 deletions(-) rename Koha/{ElasticSearch.pm => SearchEngine/Elasticsearch.pm} (98%) rename Koha/{ElasticSearch => SearchEngine/Elasticsearch}/Indexer.pm (94%) rename t/db_dependent/{Koha_ElasticSearch.t => Koha_Elasticsearch.} (94%) rename t/db_dependent/{Koha_ElasticSearch_Indexer.t => Koha_Elasticsearch_Indexer.t} (90%) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 25bf496..f846e7d 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2974,8 +2974,8 @@ sub ModZebra { if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) { # TODO abstract to a standard API that'll work for whatever - require Koha::ElasticSearch::Indexer; - my $indexer = Koha::ElasticSearch::Indexer->new( + require Koha::SearchEngine::Elasticsearch::Indexer; + my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { index => $server eq 'biblioserver' ? $Koha::SearchEngine::BIBLIOS_INDEX diff --git a/Koha/ElasticSearch.pm b/Koha/SearchEngine/Elasticsearch.pm similarity index 98% rename from Koha/ElasticSearch.pm rename to Koha/SearchEngine/Elasticsearch.pm index ee6f227..35a6540 100644 --- a/Koha/ElasticSearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -1,4 +1,4 @@ -package Koha::ElasticSearch; +package Koha::SearchEngine::Elasticsearch; # Copyright 2015 Catalyst IT # @@ -42,7 +42,7 @@ Readonly our $AUTHORITIES_INDEX => 'authorities'; =head1 NAME -Koha::ElasticSearch - Base module for things using elasticsearch +Koha::SearchEngine::Elasticsearch - Base module for things using elasticsearch =head1 ACCESSORS @@ -466,6 +466,8 @@ __END__ =item Robin Sheat C<< >> +=item Jonathan Druart C<< >> + =back =cut diff --git a/Koha/ElasticSearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm similarity index 94% rename from Koha/ElasticSearch/Indexer.pm rename to Koha/SearchEngine/Elasticsearch/Indexer.pm index 3c6d144..b35378f 100644 --- a/Koha/ElasticSearch/Indexer.pm +++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -1,4 +1,4 @@ -package Koha::ElasticSearch::Indexer; +package Koha::SearchEngine::Elasticsearch::Indexer; # Copyright 2013 Catalyst IT # @@ -19,22 +19,22 @@ package Koha::ElasticSearch::Indexer; use Carp; use Modern::Perl; -use base qw(Koha::ElasticSearch); +use base qw(Koha::SearchEngine::Elasticsearch); use Data::Dumper; # For now just marc, but we can do anything here really use Catmandu::Importer::MARC; use Catmandu::Store::ElasticSearch; -Koha::ElasticSearch::Indexer->mk_accessors(qw( store )); +Koha::SearchEngine::Elasticsearch::Indexer->mk_accessors(qw( store )); =head1 NAME -Koha::ElasticSearch::Indexer - handles adding new records to the index +Koha::SearchEngine::Elasticsearch::Indexer - handles adding new records to the index =head1 SYNOPSIS - my $indexer = Koha::ElasticSearch::Indexer->new( + my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { index => Koha::SearchEngine::BIBLIOS_INDEX } ); $indexer->drop_index(); $indexer->update_index(\@biblionumbers, \@records); diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 257f8f9..46609c0 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -39,7 +39,7 @@ provides something that can be given to elasticsearch to get answers. =cut -use base qw(Koha::ElasticSearch); +use base qw(Koha::SearchEngine::Elasticsearch); use Carp; use JSON; use List::MoreUtils qw/ each_array /; @@ -143,7 +143,7 @@ sub build_browse_query { return { query => '*' } if !defined $query; - # TODO this should come from Koha::Elasticsearch + # TODO this should come from Koha::SearchEngine::Elasticsearch my %field_whitelist = ( title => 1, author => 1, diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 9f14c3a..212a561 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -19,12 +19,12 @@ package Koha::SearchEngine::Elasticsearch::Search; =head1 NAME -Koha::SearchEngine::ElasticSearch::Search - search functions for Elasticsearch +Koha::SearchEngine::Elasticsearch::Search - search functions for Elasticsearch =head1 SYNOPSIS my $searcher = - Koha::SearchEngine::ElasticSearch::Search->new( { index => $index } ); + Koha::SearchEngine::Elasticsearch::Search->new( { index => $index } ); my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => $index } ); my $query = $builder->build_query('perl'); @@ -40,7 +40,7 @@ Koha::SearchEngine::ElasticSearch::Search - search functions for Elasticsearch use Modern::Perl; -use base qw(Koha::ElasticSearch); +use base qw(Koha::SearchEngine::Elasticsearch); use C4::Context; use Koha::ItemTypes; use Koha::AuthorisedValues; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 48f91e5..b0fdf41 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -12276,7 +12276,7 @@ $DBversion = "3.23.00.050"; if ( CheckVersion($DBversion) ) { use Koha::SearchMarcMaps; use Koha::SearchFields; - use Koha::ElasticSearch; + use Koha::SearchEngine::Elasticsearch; $dbh->do(q|INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('SearchEngine','Zebra','Choose Search Engine','','Choice')|); @@ -12339,7 +12339,7 @@ $dbh->do(q| |); # Insert default mappings - Koha::ElasticSearch->reset_elasticsearch_mappings; + Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; print "Upgrade to $DBversion done (Bug 12478 - Elasticsearch support for Koha)\n"; SetVersion($DBversion); diff --git a/installer/install.pl b/installer/install.pl index f46229b..512ca3c 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -209,8 +209,8 @@ elsif ( $step && $step == 3 ) { "fwklanguage" => $fwk_language, "list" => $list ); - use Koha::ElasticSearch; - Koha::ElasticSearch->reset_elasticsearch_mappings; + use Koha::SearchEngine::Elasticsearch; + Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; $template->param( "$op" => 1 ); } elsif ( $op && $op eq 'selectframeworks' ) { diff --git a/misc/search_tools/rebuild_elastic_search.pl b/misc/search_tools/rebuild_elastic_search.pl index 66d0cbb..6faa32c 100755 --- a/misc/search_tools/rebuild_elastic_search.pl +++ b/misc/search_tools/rebuild_elastic_search.pl @@ -86,7 +86,7 @@ use Getopt::Long; use C4::Context; use Koha::MetadataRecord::Authority; use Koha::BiblioUtils; -use Koha::ElasticSearch::Indexer; +use Koha::SearchEngine::Elasticsearch::Indexer; use MARC::Field; use MARC::Record; use Modern::Perl; @@ -136,7 +136,7 @@ if ($index_biblios) { $records->next(); } } - do_reindex($next, $Koha::ElasticSearch::BIBLIOS_INDEX); + do_reindex($next, $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX); } if ($index_authorities) { _log(1, "Indexing authorities\n"); @@ -153,13 +153,13 @@ if ($index_authorities) { $records->next(); } } - do_reindex($next, $Koha::ElasticSearch::AUTHORITIES_INDEX); + do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); } sub do_reindex { my ( $next, $index_name ) = @_; - my $indexer = Koha::ElasticSearch::Indexer->new( { index => $index_name } ); + my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { index => $index_name } ); if ($delete) { # We know it's safe to not recreate the indexer because update_index diff --git a/t/00-load.t b/t/00-load.t index ab4b08f..6c8b838 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -82,7 +82,7 @@ sub is_testable { @needed_module_names = ( 'SOAP::Lite', 'Crypt::GCrypt', 'Digest::SHA', 'Convert::BaseN' ); } - elsif ( $module_name =~ /Koha::ElasticSearch::Indexer/xsm ) { + elsif ( $module_name =~ /Koha::SearchEngine::Elasticsearch::Indexer/xsm ) { @needed_module_names = ( 'Catmandu::Importer::MARC', 'Catmandu::Store::ElasticSearch' ); } diff --git a/t/db_dependent/Koha_ElasticSearch.t b/t/db_dependent/Koha_Elasticsearch. similarity index 94% rename from t/db_dependent/Koha_ElasticSearch.t rename to t/db_dependent/Koha_Elasticsearch. index d9ea31f..bad08d2 100644 --- a/t/db_dependent/Koha_ElasticSearch.t +++ b/t/db_dependent/Koha_Elasticsearch. @@ -20,4 +20,4 @@ use warnings; use Test::More tests => 1; # last test to print -use_ok('Koha::ElasticSearch'); +use_ok('Koha::Search::Engine::Elasticsearch'); diff --git a/t/db_dependent/Koha_ElasticSearch_Indexer.t b/t/db_dependent/Koha_Elasticsearch_Indexer.t similarity index 90% rename from t/db_dependent/Koha_ElasticSearch_Indexer.t rename to t/db_dependent/Koha_Elasticsearch_Indexer.t index 626079d..04a8e2a 100644 --- a/t/db_dependent/Koha_ElasticSearch_Indexer.t +++ b/t/db_dependent/Koha_Elasticsearch_Indexer.t @@ -21,11 +21,11 @@ use Test::More tests => 5; use MARC::Record; -use_ok('Koha::ElasticSearch::Indexer'); +use_ok('Koha::SearchEngine::Elasticsearch::Indexer'); my $indexer; ok( - $indexer = Koha::ElasticSearch::Indexer->new({ 'index' => 'biblio' }), + $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblio' }), 'Creating new indexer object' ); diff --git a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t index ac20414..2bcd83c 100644 --- a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t +++ b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t @@ -29,7 +29,7 @@ ok( my $searcher = Koha::SearchEngine::Elasticsearch::Search->new( { 'nodes' => ['localhost:9200'], 'index' => 'mydb' } ), - 'Creating a Koha::ElasticSearch::Search object' + 'Creating a Koha::SearchEngine::Elasticsearch::Search object' ); is( $searcher->index, 'mydb', 'Testing basic accessor' ); -- 2.1.4