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);
}
}
+ # 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);
+ }
}
}