Bugzilla – Attachment 169099 Details for
Bug 37333
Search filters using OR are not correctly grouped
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37333: Group search terms in a saved filter
Bug-37333-Group-search-terms-in-a-saved-filter.patch (text/plain), 4.45 KB, created by
Martin Renvoize (ashimema)
on 2024-07-17 16:07:24 UTC
(
hide
)
Description:
Bug 37333: Group search terms in a saved filter
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-07-17 16:07:24 UTC
Size:
4.45 KB
patch
obsolete
>From 0f72b9bb31eeae48a88bbcbcc8b535596874fe42 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 11 Jul 2024 19:38:16 +0000 >Subject: [PATCH] Bug 37333: Group search terms in a saved filter > >This patch surrounds the expanded query of a search filter in parnetheses to correctly >group the terms when searching > >To test: > 1 - Enable system preference SavedSearchFilters > 2 - In staff client, perform an advanced search for: > subject:internet OR subject:programming > 3 - Note results > 4 - Save search as filter, enabled in staff client and opac > 5 - Search for 'a' > 6 - Apply filter from top of facets on left hand side > 7 - Note results didn't change > 8 - Apply patch, restart all > 9 - Reload search, it now limits correctly >10 - Test on OPAC >11 - Test on both Zebra and Elastic >12 - Sign off :-) > >Signed-off-by: Jake Deery <jake.deery@ptfs-europe.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/SearchFilter.pm | 3 +- > t/db_dependent/Koha/SearchFilters.t | 77 +++++++++++++++++++++++++++++ > 2 files changed, 79 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Koha/SearchFilters.t > >diff --git a/Koha/SearchFilter.pm b/Koha/SearchFilter.pm >index 3683a89b28e..9694c1e31ca 100644 >--- a/Koha/SearchFilter.pm >+++ b/Koha/SearchFilter.pm >@@ -51,7 +51,7 @@ sub expand_filter { > my $operands = $query->{operands}; > my $indexes = $query->{indexes}; > >- my $query_limit; >+ my $query_limit = "("; > for( my $i = 0; $i < scalar @$operands; $i++ ){ > next unless @$operands[$i]; > my $index = @$indexes[$i] ? @$indexes[$i] . "=" : ""; >@@ -61,6 +61,7 @@ sub expand_filter { > my $limit = $operator . $index . $query; > $query_limit .= $limit; > } >+ $query_limit .= ")"; > > return ($limits, $query_limit); > } >diff --git a/t/db_dependent/Koha/SearchFilters.t b/t/db_dependent/Koha/SearchFilters.t >new file mode 100755 >index 00000000000..81a304ba273 >--- /dev/null >+++ b/t/db_dependent/Koha/SearchFilters.t >@@ -0,0 +1,77 @@ >+#!/usr/bin/perl >+ >+# Copyright 2024 ByWater Solutions >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 4; >+ >+use Koha::Database; >+use Koha::SearchFilters; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $original_count = Koha::SearchFilters->count(); >+ >+my $search_filter = Koha::SearchFilter->new( >+ { >+ name => "Test", >+ query => q|{"operands":["programming","internet"],"operators":["OR"],"indexes":["su","su"]}|, >+ limits => q|{"limits":[]}|, >+ opac => 1, >+ staff_client => 1 >+ } >+)->store; >+ >+is( Koha::SearchFilters->search()->count(), $original_count + 1, "New filter is added" ); >+is( >+ Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count + 1, >+ "Searching by opac returns the filter if set" >+); >+$search_filter->opac(0)->store(); >+is( >+ Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count, >+ "Searching by opac doesn't return the filter if not set" >+); >+ >+subtest 'expand_filter tests' => sub { >+ >+ plan tests => 2; >+ >+ my $search_filter = Koha::SearchFilter->new( >+ { >+ name => "Test", >+ query => q|{"operands":["programming","internet"],"operators":["OR"],"indexes":["su","su"]}|, >+ limits => q|{"limits":["mc-itype,phr:BK","fic:0"]}|, >+ opac => 1, >+ staff_client => 1 >+ } >+ )->store; >+ >+ my ( $limits, $query_limit ) = $search_filter->expand_filter(); >+ >+ is_deeply( $limits, [ 'mc-itype,phr:BK', 'fic:0' ], "Limit from filter is correctly expanded" ); >+ is( $query_limit, '(su=(programming) OR su=(internet))', "Query from filter is correctly expanded and grouped" ); >+ >+}; >+ >+$schema->storage->txn_rollback; >-- >2.45.2
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 37333
:
168864
|
168894
| 169099 |
169308