Bug 17170: Handle search filters in query builders

This patch updates the query building code to expand filters when searching
and pass them back as part of the cgi and descriptive search strings

Sponsored-by: Sponsored by: Round Rock Public Library [https://www.roundrocktexas.gov/departments/library/]

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2022-03-17 10:50:02 +00:00 committed by Tomas Cohen Arazi
parent 8907b6c3a6
commit a97a6b28d2
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 12 additions and 2 deletions

View File

@ -21,6 +21,7 @@ use C4::Biblio qw( TransformMarcToKoha GetMarcFromKohaField GetFrameworkCode Get
use C4::Koha qw( getFacets GetVariationsOfISBN GetNormalizedUPC GetNormalizedEAN GetNormalizedOCLCNumber GetNormalizedISBN getitemtypeimagelocation );
use Koha::DateUtils;
use Koha::Libraries;
use Koha::SearchEngine::QueryBuilder;
use Lingua::Stem;
use XML::Simple;
use C4::XSLT qw( XSLTParse4Display );
@ -33,6 +34,7 @@ use Koha::Logger;
use Koha::Patrons;
use Koha::Recalls;
use Koha::RecordProcessor;
use Koha::SearchFilters;
use URI::Escape;
use Business::ISBN;
use MARC::Record;
@ -1538,7 +1540,6 @@ sub buildQuery {
}
Koha::Logger->get->debug("QUERY BEFORE LIMITS: >$query<");
# Normalize the query and limit strings
# This is flawed , means we can't search anything with : in it
# if user wants to do ccl or cql, start the query with that

View File

@ -806,7 +806,7 @@ sub _convert_index_strings_freeform {
# Lower case field names
$search =~ s/($field_name_pattern)(?:,[\w-]*)?($multi_field_pattern):/\L$1\E$2:/og;
# Resolve possible field aliases
$search =~ s/($field_name_pattern)($multi_field_pattern):/(exists $index_field_convert{$1} ? $index_field_convert{$1} : $1)."$2:"/oge;
$search =~ s/($field_name_pattern)($multi_field_pattern):/(exists $index_field_convert{$1} ? $index_field_convert{$1} : $1).($1 eq 'kw' ? "$2" : "$2:")/oge;
return $search;
}
@ -1069,6 +1069,15 @@ sub _fix_limit_special_cases {
next unless defined($start) && defined($end);
push @new_lim, "date-of-publication:[$start TO $end]";
}
elsif( $l =~ /^search_filter:/ ){
my ($filter_id) = ( $l =~ /^search_filter:(.*)$/ );
my $search_filter = Koha::SearchFilters->find( $filter_id );
next unless $search_filter;
my $expanded = $search_filter->expand_filter;
foreach my $e ( @{$self->_fix_limit_special_cases($expanded)} ) {
push @new_lim, $self->clean_search_term( $e );
}
}
elsif ( $l =~ /^yr,st-numeric[=:]/ ) {
my ($date) = ( $l =~ /^yr,st-numeric[=:](.*)$/ );
next unless defined($date);