Bugzilla – Attachment 61783 Details for
Bug 9988
Leave larger authority merges to merge_authorities cronjob (pref AuthorityMergeLimit)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9988: Add extract_biblionumber to Koha/SearchEngine
Bug-9988-Add-extractbiblionumber-to-KohaSearchEngi.patch (text/plain), 6.21 KB, created by
Marcel de Rooy
on 2017-04-03 08:31:17 UTC
(
hide
)
Description:
Bug 9988: Add extract_biblionumber to Koha/SearchEngine
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-04-03 08:31:17 UTC
Size:
6.21 KB
patch
obsolete
>From ab6dc709551e62094b72bf0c40a0f686327430fe Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 15 Feb 2017 15:48:17 +0100 >Subject: [PATCH] Bug 9988: Add extract_biblionumber to Koha/SearchEngine >Content-Type: text/plain; charset=utf-8 > >When we will replace the Zebra code in sub merge, we will call SearchEngine >to pass records and we need a routine to extract a biblionumber from >a search result record. A record from Zebra still must be converted to >MARC::Record. This is no longer needed for a ElasticSearch record. > >Test plan: >Run t/db_dependent/Koha/SearchEngine/Search.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/SearchEngine/Elasticsearch/Search.pm | 16 ++++++++ > Koha/SearchEngine/Search.pm | 23 ++++++++++- > Koha/SearchEngine/Zebra/Search.pm | 17 +++++++++ > t/db_dependent/Koha/SearchEngine/Search.t | 63 +++++++++++++++++++++++++++++++ > 4 files changed, 118 insertions(+), 1 deletion(-) > create mode 100644 t/db_dependent/Koha/SearchEngine/Search.t > >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index ae2dd4c..26bc4fc 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -45,6 +45,7 @@ use C4::Context; > use Koha::ItemTypes; > use Koha::AuthorisedValues; > use Koha::SearchEngine::QueryBuilder; >+use Koha::SearchEngine::Search; > use MARC::Record; > use Catmandu::Store::ElasticSearch; > >@@ -344,6 +345,21 @@ sub simple_search_compat { > return (undef, \@records, $results->total); > } > >+=head2 extract_biblionumber >+ >+ my $biblionumber = $searcher->extract_biblionumber( $searchresult ); >+ >+$searchresult comes from simple_search_compat. >+ >+Returns the biblionumber from the search result record. >+ >+=cut >+ >+sub extract_biblionumber { >+ my ( $self, $searchresultrecord ) = @_; >+ return Koha::SearchEngine::Search::extract_biblionumber( $searchresultrecord ); >+} >+ > =head2 json2marc > > my $marc = $self->json2marc($marc_json); >diff --git a/Koha/SearchEngine/Search.pm b/Koha/SearchEngine/Search.pm >index 7d928d7..fdaf7d3 100644 >--- a/Koha/SearchEngine/Search.pm >+++ b/Koha/SearchEngine/Search.pm >@@ -43,8 +43,9 @@ Creates a new C<Search> of whatever the relevant type is. > > =cut > >-use C4::Context; > use Modern::Perl; >+use C4::Context; >+use C4::Biblio qw//; > > sub new { > my $engine = C4::Context->preference("SearchEngine") // 'Zebra'; >@@ -55,4 +56,24 @@ sub new { > return $class->new(@_); > } > >+=head2 extract_biblionumber >+ >+ my $biblionumber = $searcher->extract_biblionumber( $marc ); >+ >+Returns the biblionumber from $marc. The routine is called from the >+extract_biblionumber method of the specific search engine. >+ >+=cut >+ >+sub extract_biblionumber { >+ my ( $record ) = @_; >+ return if ref($record) ne 'MARC::Record'; >+ my ( $biblionumbertagfield, $biblionumbertagsubfield ) = C4::Biblio::GetMarcFromKohaField( 'biblio.biblionumber', '' ); >+ if( $biblionumbertagfield < 10 ) { >+ my $controlfield = $record->field( $biblionumbertagfield ); >+ return $controlfield ? $controlfield->data : undef; >+ } >+ return $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield ); >+} >+ > 1; >diff --git a/Koha/SearchEngine/Zebra/Search.pm b/Koha/SearchEngine/Zebra/Search.pm >index cb69e22..2fb45da 100644 >--- a/Koha/SearchEngine/Zebra/Search.pm >+++ b/Koha/SearchEngine/Zebra/Search.pm >@@ -23,6 +23,7 @@ use base qw(Class::Accessor); > > use C4::Search; # :( > use C4::AuthoritiesMarc; >+use Koha::SearchEngine::Search; > > =head1 NAME > >@@ -76,6 +77,22 @@ sub simple_search_compat { > return C4::Search::SimpleSearch(@_); > } > >+=head2 extract_biblionumber >+ >+ my $biblionumber = $searcher->extract_biblionumber( $searchresult ); >+ >+$searchresult comes from simple_search_compat. >+ >+Returns the biblionumber from the search result record. >+ >+=cut >+ >+sub extract_biblionumber { >+ my ( $self, $searchresultrecord ) = @_; >+ my $record = C4::Search::new_record_from_zebra( 'biblioserver', $searchresultrecord ); >+ return Koha::SearchEngine::Search::extract_biblionumber( $record ); >+} >+ > =head2 search_auth_compat > > This passes the search query on to C4::AuthoritiesMarc::SearchAuthorities >diff --git a/t/db_dependent/Koha/SearchEngine/Search.t b/t/db_dependent/Koha/SearchEngine/Search.t >new file mode 100644 >index 0000000..bbef2f1 >--- /dev/null >+++ b/t/db_dependent/Koha/SearchEngine/Search.t >@@ -0,0 +1,63 @@ >+#!/usr/bin/perl >+ >+# Tests for Koha/SearchEngine/Search >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+ >+use MARC::Field; >+use MARC::Record; >+use Test::MockModule; >+use Test::MockObject; >+ >+use t::lib::Mocks; >+ >+#use C4::Biblio qw//; >+use Koha::Database; >+use Koha::SearchEngine::Search; >+ >+BEGIN { >+ my $mock = Test::MockObject->new(); >+ $mock->fake_module( 'Catmandu::Store::ElasticSearch' ); >+} >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+subtest 'Test extract_biblionumber' => sub { >+ plan tests => 2; >+ >+ t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); >+ my $biblio_mod = Test::MockModule->new( 'C4::Biblio' ); >+ my $search_mod = Test::MockModule->new( 'C4::Search' ); >+ my $koha_fields = [ '001', '' ]; >+ $biblio_mod->mock( 'GetMarcFromKohaField', sub { return @$koha_fields; }); >+ $search_mod->mock( 'new_record_from_zebra', \&test_record ); >+ >+ # Extract using 001 >+ my $searcher = Koha::SearchEngine::Search->new; >+ my $bibno = $searcher->extract_biblionumber( 'fake_result' ); >+ is( $bibno, 3456, 'Extracted biblio number for Zebra' ); >+ >+ # Now use 999c with Elasticsearch >+ t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); >+ $search_mod->unmock( 'new_record_from_zebra' ); >+ $koha_fields = [ '999', 'c' ]; >+ $searcher = Koha::SearchEngine::Search->new({ index => 'biblios' }); >+ $bibno = $searcher->extract_biblionumber( test_record() ); >+ is( $bibno, 4567, 'Extracted biblio number for Zebra' ); >+}; >+ >+# -- Helper routine >+sub test_record { >+ my $marc = MARC::Record->new; >+ $marc->append_fields( >+ MARC::Field->new( '001', '3456' ), >+ MARC::Field->new( '245', '', '', a => 'Some title' ), >+ MARC::Field->new( '999', '', '', c => '4567' ), >+ ); >+ return $marc; >+} >+ >+$schema->storage->txn_rollback; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9988
:
59158
|
59159
|
60256
|
60257
|
60258
|
60259
|
60594
|
60595
|
60596
|
60597
|
60598
|
60599
|
60600
|
60601
|
60602
|
60603
|
60604
|
60605
|
60606
|
60607
|
60668
|
60669
|
60670
|
60671
|
60672
|
60673
|
60674
|
60675
|
61306
|
61307
|
61308
|
61309
|
61779
|
61780
|
61781
|
61782
|
61783
|
61784
|
61785
|
61786
|
61787
|
61788
|
61789
|
61790
|
61791
|
61792
|
61890
|
61891
|
61892
|
61893
|
61894
|
61895
|
61897
|
61898
|
61899
|
61900
|
61901
|
61902
|
61903
|
61904
|
61912
|
61913
|
61914
|
61915
|
61916
|
61917
|
61918
|
61919
|
61920
|
61921
|
61922
|
61923
|
61924
|
61925
|
62055
|
62123
|
62124
|
62125
|
62126
|
62127
|
62128
|
62129
|
62130
|
62131
|
62132
|
62133
|
62134
|
62135
|
62136
|
62137