From 608a9cee92f7dbb19670d058d2f74b3f7fd44841 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Thu, 12 Dec 2024 18:10:39 +0200 Subject: [PATCH] Bug 38691 - WIP - FRBRizeEditions should look directly in the local catalog for other editions Currently FRBRizeEditions only looks from a remote service for other editions for a given ISBN. Local queries are only done to validate that the local database has the results found from the external source. Instead/on-the-side we should do a local lookup for other editions of the same biblio. WIP This is a result of a quick test to make the FRBRizeEditions-feature do something and have a PoC of what it actually does. Hopefully this will help somebody someday. --- lib/C4/XISBN.pm | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/C4/XISBN.pm b/lib/C4/XISBN.pm index 67d89ea..321fe47 100644 --- a/lib/C4/XISBN.pm +++ b/lib/C4/XISBN.pm @@ -50,27 +50,31 @@ This module provides facilities for retrieving ThingISBN and XISBN content in Ko =cut -sub _get_biblio_from_xisbn { +sub _get_biblios_from_xisbn { my $xisbn = shift; my $dbh = C4::Context->dbh; my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); - my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( "nb=$xisbn", 0, 1 ); + my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( "nb=$xisbn", 0, 50 ); return unless ( !$errors && scalar @$results ); - my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[0] ); - my $biblionumber = C4::Biblio::TransformMarcToKoha({ - kohafields => ['biblio.biblionumber'], - record => $record - })->{biblionumber}; - return unless $biblionumber; - - my $biblio = Koha::Biblios->find( $biblionumber ); - return unless $biblio; - my $isbn = $biblio->biblioitem->isbn; - $biblio = $biblio->unblessed; - $biblio->{normalized_isbn} = GetNormalizedISBN($isbn); - return $biblio; + my @biblios; + for my $result (@$results) { + my $record = C4::Search::new_record_from_zebra( 'biblioserver', $result ); + my $biblionumber = C4::Biblio::TransformMarcToKoha({ + kohafields => ['biblio.biblionumber'], + record => $record + })->{biblionumber}; + next unless $biblionumber; + + my $biblio = Koha::Biblios->find( $biblionumber ); + next unless $biblio; + my $isbn = $biblio->biblioitem->isbn; + $biblio = $biblio->unblessed; + $biblio->{normalized_isbn} = GetNormalizedISBN($isbn); + push(@biblios, $biblio); + } + return \@biblios; } =head1 get_xisbns($isbn, $biblionumber); @@ -97,7 +101,7 @@ sub get_xisbns { $syndetics_response = {isbn => \@syndetics_response}; } - $response->{isbn} = [ @{ $syndetics_response->{isbn} or [] }, @{ $thing_response->{isbn} or [] } ]; + $response->{isbn} = [{content => $isbn}, @{ $syndetics_response->{isbn} or [] }, @{ $thing_response->{isbn} or [] } ]; my @xisbns; my $unique_xisbns; # a hashref @@ -105,9 +109,8 @@ sub get_xisbns { for my $response_data( @{ $response->{ isbn } } ) { next if $unique_xisbns->{ $response_data->{content} }; $unique_xisbns->{ $response_data->{content} }++; - my $xbiblio= _get_biblio_from_xisbn($response_data->{content}); - next unless $xbiblio; - push @xisbns, $xbiblio if $xbiblio && $xbiblio->{biblionumber} ne $biblionumber; + my $xbiblios= _get_biblios_from_xisbn($response_data->{content}); + push @xisbns, grep {$_->{biblionumber} ne $biblionumber} @$xbiblios; } if ( wantarray ) { return (\@xisbns, $errors); -- 2.34.1