From 8712cc95bef9878a3ff27a6433e5ad819542864c Mon Sep 17 00:00:00 2001 From: Slava Shishkin Date: Wed, 27 Apr 2022 00:22:54 +0300 Subject: [PATCH] Bug 23919: Items search by ISBN variations and ISSN variations Signed-off-by: David Nind Signed-off-by: Kyle M Hall --- C4/Items.pm | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 80c224b4cdd..443242be5d9 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1299,6 +1299,22 @@ sub _SearchItems_build_where_fragment { } $column = "ExtractValue($sqlfield, '$xpath')"; } + } + elsif ($field eq 'isbn') { + if ( C4::Context->preference("SearchWithISBNVariations") and $query ) { + my @isbns = C4::Koha::GetVariationsOfISBN( $query ); + $query = []; + push @$query, @isbns; + } + $column = $field; + } + elsif ($field eq 'issn') { + if ( C4::Context->preference("SearchWithISSNVariations") and $query ) { + my @issns = C4::Koha::GetVariationsOfISSN( $query ); + $query = []; + push @$query, @issns; + } + $column = $field; } else { $column = $field; } @@ -1308,15 +1324,23 @@ sub _SearchItems_build_where_fragment { } if (ref $query eq 'ARRAY') { - if ($op eq '=') { - $op = 'IN'; - } elsif ($op eq '!=') { - $op = 'NOT IN'; + if ($op eq 'like') { + $where_fragment = { + str => "($column LIKE " . join (" OR $column LIKE ", ('?') x @$query ) . ")", + args => $query, + }; + } + else { + if ($op eq '=') { + $op = 'IN'; + } elsif ($op eq '!=') { + $op = 'NOT IN'; + } + $where_fragment = { + str => "$column $op (" . join (',', ('?') x @$query) . ")", + args => $query, + }; } - $where_fragment = { - str => "$column $op (" . join (',', ('?') x @$query) . ")", - args => $query, - }; } elsif ( $op eq 'is' ) { $where_fragment = { str => "$column $op $query", -- 2.30.2