Bugzilla – Attachment 124574 Details for
Bug 28847
Branch limits while searching should be expanded in query building and not in CGI
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28847: Move SearchLimitLibrary code to QueryBuilder Modules
Bug-28847-Move-SearchLimitLibrary-code-to-QueryBui.patch (text/plain), 8.47 KB, created by
Nick Clemens (kidclamp)
on 2021-09-07 12:02:04 UTC
(
hide
)
Description:
Bug 28847: Move SearchLimitLibrary code to QueryBuilder Modules
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2021-09-07 12:02:04 UTC
Size:
8.47 KB
patch
obsolete
>From d16e0dcccaa1a86e93cbef138c020e7070807a3c Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 12 Aug 2021 11:02:39 +0000 >Subject: [PATCH] Bug 28847: Move SearchLimitLibrary code to QueryBuilder > Modules > >This patch removes the code from the search scripts into QueryBuilder >modules. > >To test: >1 - Have a library group defined as a search group for both staff and opac >2 - Search on staff client and opac with that group limit and a single branch limit >3 - Note your results/counts >4 - Note the visuals of the search description >5 - Apply patch >6 - Repeat searches >7 - All should work as before > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> >--- > C4/Search.pm | 30 ++++++++++++++ > .../Elasticsearch/QueryBuilder.pm | 26 +++++++++++++ > catalogue/search.pl | 39 ------------------- > opac/opac-search.pl | 39 ------------------- > 4 files changed, 56 insertions(+), 78 deletions(-) > >diff --git a/C4/Search.pm b/C4/Search.pm >index 5814c5f5dc..54b88d5d77 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -1472,6 +1472,36 @@ sub buildQuery { > $limit_cgi .= "&limit=" . uri_escape_utf8($this_limit); > $limit_desc .= " $this_limit"; > } >+ elsif ( $this_limit =~ 'multibranchlimit|^branch' ) { >+ $limit_cgi .= "&limit=" . uri_escape_utf8($this_limit); >+ $limit .= " and " if $limit || $query; >+ my $branchfield = C4::Context->preference('SearchLimitLibrary'); >+ my @branchcodes; >+ if( $this_limit =~ 'multibranchlimit' ){ >+ my ($group_id) = ( $this_limit =~ /^multibranchlimit:(.*)$/ ); >+ my $search_group = Koha::Library::Groups->find( $group_id ); >+ @branchcodes = map { $_->branchcode } $search_group->all_libraries; >+ @branchcodes = sort { $a cmp $b } @branchcodes; >+ } else { >+ @branchcodes = ( $this_limit =~ /^branch:(.*)$/ ); >+ } >+ >+ if (@branchcodes) { >+ if ( $branchfield eq "homebranch" ) { >+ $this_limit = sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes; >+ } >+ elsif ( $branchfield eq "holdingbranch" ) { >+ $this_limit = sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes; >+ } >+ else { >+ $this_limit = sprintf "(%s or %s)", >+ join( " or ", map { 'homebranch: ' . $_ } @branchcodes ), >+ join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes ); >+ } >+ } >+ $limit .= "$this_limit"; >+ $limit_desc .= " $this_limit"; >+ } > > # Regular old limits > else { >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index ab292b1379..cce55f0f8d 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -1011,6 +1011,32 @@ sub _fix_limit_special_cases { > $date = $self->_modify_string_by_type(type => 'st-year', operand => $date); > push @new_lim, "date-of-publication:$date"; > } >+ elsif ( $l =~ 'multibranchlimit|^branch' ) { >+ my $branchfield = C4::Context->preference('SearchLimitLibrary'); >+ my @branchcodes; >+ if( $l =~ 'multibranchlimit' ) { >+ my ($group_id) = ( $l =~ /^multibranchlimit:(.*)$/ ); >+ my $search_group = Koha::Library::Groups->find( $group_id ); >+ @branchcodes = map { $_->branchcode } $search_group->all_libraries; >+ @branchcodes = sort { $a cmp $b } @branchcodes; >+ } else { >+ @branchcodes = ( $l =~ /^branch:(.*)$/ ); >+ } >+ >+ if (@branchcodes) { >+ if ( $branchfield eq "homebranch" ) { >+ push @new_lim, sprintf "(%s)", join " OR ", map { 'homebranch: ' . $_ } @branchcodes; >+ } >+ elsif ( $branchfield eq "holdingbranch" ) { >+ push @new_lim, sprintf "(%s)", join " OR ", map { 'holdingbranch: ' . $_ } @branchcodes; >+ } >+ else { >+ push @new_lim, sprintf "(%s OR %s)", >+ join( " OR ", map { 'homebranch: ' . $_ } @branchcodes ), >+ join( " OR ", map { 'holdingbranch: ' . $_ } @branchcodes ); >+ } >+ } >+ } > elsif ( $l =~ /^available$/ ) { > push @new_lim, 'onloan:false'; > } >diff --git a/catalogue/search.pl b/catalogue/search.pl >index 8ed6ff3181..9c99bbe4f3 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -378,45 +378,6 @@ my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); > my %is_nolimit = map { $_ => 1 } @nolimits; > @limits = grep { not $is_nolimit{$_} } @limits; > >-if ( $params->{'multibranchlimit'} ) { >- my $branchfield = C4::Context->preference('SearchLimitLibrary'); >- my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); >- my @branchcodes = map { $_->branchcode } $search_group->all_libraries; >- >- if (@branchcodes) { >- if ( $branchfield eq "homebranch" ) { >- push @limits, sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes; >- } >- elsif ( $branchfield eq "holdingbranch" ) { >- push @limits, sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes; >- } >- else { >- push @limits, sprintf "(%s or %s)", >- join( " or ", map { 'homebranch: ' . $_ } @branchcodes ), >- join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes ); >- } >- } >-} >- >-for ( my $i=0; $i<@limits; $i++ ) { >- if ( $limits[$i] =~ /^branch:/ ) { >- my $branchfield = C4::Context->preference('SearchLimitLibrary'); >- if ( $branchfield eq "homebranch" ) { >- $limits[$i] =~ s/branch/homebranch/; >- } >- elsif ( $branchfield eq "holdingbranch" ) { >- $limits[$i] =~ s/branch/holdingbranch/; >- } >- else { >- my $homebranchlimit = $limits[$i]; >- my $holdingbranchlimit = $limits[$i]; >- $homebranchlimit =~ s/branch/homebranch/; >- $holdingbranchlimit =~ s/branch/holdingbranch/; >- $limits[$i] = "($homebranchlimit or $holdingbranchlimit)"; >- } >- } >-} >- > my $available; > foreach my $limit(@limits) { > if ($limit =~/available/) { >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 0ea238da3d..f7254a1f20 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -446,45 +446,6 @@ if (@searchCategories > 0) { > > @limits = map { uri_unescape($_) } @limits; > >-if ( $params->{'multibranchlimit'} || ( $branch_group_limit && $branch_group_limit =~ /^multibranchlimit-/ ) ) { >- my $branchfield = C4::Context->preference('SearchLimitLibrary'); >- my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); >- >- my @branchcodes = map { $_->branchcode } $search_group->all_libraries; >- >- if (@branchcodes) { >- if ( $branchfield eq "homebranch" ) { >- push @limits, sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes; >- } >- elsif ( $branchfield eq "holdingbranch" ) { >- push @limits, sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes; >- } >- else { >- push @limits, sprintf "(%s or %s)", >- join( " or ", map { 'homebranch: ' . $_ } @branchcodes ), >- join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes ); >- } >- } >-} >- >-for ( my $i=0; $i<@limits; $i++ ) { >- if ( $limits[$i] =~ /^branch:/ ) { >- my $branchfield = C4::Context->preference('SearchLimitLibrary'); >- if ( $branchfield eq "homebranch" ) { >- $limits[$i] =~ s/branch/homebranch/; >- } >- elsif ( $branchfield eq "holdingbranch" ) { >- $limits[$i] =~ s/branch/holdingbranch/; >- } >- else { >- my $homebranchlimit = $limits[$i]; >- my $holdingbranchlimit = $limits[$i]; >- $homebranchlimit =~ s/branch/homebranch/; >- $holdingbranchlimit =~ s/branch/holdingbranch/; >- $limits[$i] = "($homebranchlimit or $holdingbranchlimit)"; >- } >- } >-} > > my $available; > foreach my $limit(@limits) { >-- >2.20.1
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 28847
:
123807
|
123808
|
123809
|
123830
|
123832
|
123833
|
123835
|
123836
|
123837
|
123841
|
124574
|
124575
|
124576
|
124577
|
124797
|
124831
|
125017
|
125018
|
125019
|
125020
|
125021
|
125022
|
126827