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>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
2accac5fd9
commit
6cb3d72f49
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
Loading…
Reference in New Issue