From: Bill Erickson Date: Fri, 1 Feb 2013 17:23:19 +0000 (-0500) Subject: Z39 Batch ML X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f7aca6d8e7498e10b40defe9ca53a8578768fa38;p=working%2FEvergreen.git Z39 Batch ML Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm index a217f7b0a7..c508fd5a84 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm @@ -666,9 +666,6 @@ sub send_and_queue_bucket_searches { my $bre_id = delete $search->{bre_id}; $search->{limit} = $search_limit; - $logger->info("z39 firing bucket search " . - OpenSRF::Utils::JSON->perl2JSON($search)); - # toss it onto the multi-pile my $req = $multi_ses->request( 'open-ils.search.z3950.search_class', $e->authtoken, $search); @@ -794,12 +791,63 @@ sub compile_bucket_zsearch { } } + # To avoid searching on clumped ISBN values and/or ISBNs with extra + # junk [e.g. 9781405144094 (hardcover : alk. paper)], send ISBN values + # through a normalizer which returns a clean list of values. For each + # extracted ISBN, clone the search so that every ISBN is covered. + # TODO: do we need similar treatment for other ident fields? + for my $bre_id (keys %z_searches) { + for my $src (keys %{$z_searches{$bre_id}}) { + + my $blob = $z_searches{$bre_id}{$src}; + + if (my $isbn = $blob->{search}{isbn}) { + next if $isbn =~ /^[A-Za-z0-9]+$/; # clean and single + + my $clean_str = $e->json_query({ + from => ['translate_isbn1013', $isbn]})->[0]; + + next unless ref $clean_str and + $clean_str = $clean_str->{translate_isbn1013}; + + my @isbn_list = split(/\s/, $clean_str); + + if (@isbn_list == 1) { + $blob->{search}{isbn} = $isbn_list[0]; + next; + } + + # create a new container for the set of searches + $z_searches{$bre_id}{$src} = []; + + my $cur_blob; + for my $idx (0..$#isbn_list) { + my $clean_isbn = $isbn_list[$idx]; + if ($idx == 0) { + $cur_blob = $blob; + } else { + # clone + $logger->info("z30 cloning search for clean ISBN $clean_isbn"); + $cur_blob = OpenSRF::Utils::JSON->JSON2perl( + OpenSRF::Utils::JSON->perl2JSON($blob)); + } + $cur_blob->{search}{isbn} = $clean_isbn; + push(@{$z_searches{$bre_id}{$src}}, $cur_blob); + $logger->info("z30 clean ISBN $clean_isbn"); + } + } + } + } + # let's turn this into something slightly more digestable my @searches; for my $bre_id (keys %z_searches) { - for my $blob (values %{$z_searches{$bre_id}}) { - $blob->{bre_id} = $bre_id; - push(@searches, $blob); + for my $blobset (values %{$z_searches{$bre_id}}) { + $blobset = [$blobset] unless ref $blobset eq 'ARRAY'; + for my $blob (@$blobset) { + $blob->{bre_id} = $bre_id; + push(@searches, $blob); + } } }