Bugzilla – Attachment 134263 Details for
Bug 30639
Patron search does not split search terms
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30639: Split search terms for patron search
Bug-30639-Split-search-terms-for-patron-search.patch (text/plain), 5.70 KB, created by
Nick Clemens (kidclamp)
on 2022-04-28 13:43:40 UTC
(
hide
)
Description:
Bug 30639: Split search terms for patron search
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-04-28 13:43:40 UTC
Size:
5.70 KB
patch
obsolete
>From a62be7a0203a710a2436cc5370bb27cb117da72a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 28 Apr 2022 14:42:04 +0200 >Subject: [PATCH] Bug 30639: Split search terms for patron search > >If several terms are passed we should split them. > >Test plan: >Search for "edna acosta" (without quotes) in the filters from the left >side of the main patron search >Do some regression tests > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../prog/en/includes/patron-search.inc | 29 ++++++++++++++----- > t/db_dependent/selenium/patrons_search.t | 28 +++++++++++++++++- > 2 files changed, 49 insertions(+), 8 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >index ec68d3620a..b1f65fcf98 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >@@ -296,8 +296,9 @@ > return { "like": start_with + "%" } > }, > "-and": function(){ >- let filter = $("#search_patron_filter").val(); >- if (!filter) return ""; >+ let pattern = $("#search_patron_filter").val(); >+ if (!pattern) return ""; >+ let patterns = pattern.split(' ').filter(function(s){ return s.length }); > > let filters = []; > let search_type = $("#searchtype_filter").val() || "contain"; >@@ -305,14 +306,28 @@ > if ( !search_fields ) { > search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' | html %]"; > } >- search_fields.split(',').forEach(function(e,i){ >- filters.push({["me."+e]:{"like":(search_type == "contain" ? "%" : "" ) + filter + "%"}}); >+ >+ let subquery_and = []; >+ patterns.forEach(function(pattern,i){ >+ let sub_or = []; >+ search_fields.split(',').forEach(function(attr,ii){ >+ sub_or.push({["me."+attr]:{"like":(search_type == "contain" ? "%" : "" ) + pattern + "%"}}); >+ }); >+ subquery_and.push(sub_or); > }); >+ filters.push({"-and": subquery_and}); >+ > [% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %] >- filters.push({ >- "extended_attributes.value": { "like": "%" + filter + (search_type == "contain" ? "%" : "" )}, >- "extended_attributes.code": extended_attribute_types >+ subquery_and = []; >+ patterns.forEach(function(pattern,i){ >+ let sub_or = []; >+ sub_or.push({ >+ "extended_attributes.value": { "like": "%" + pattern + (search_type == "contain" ? "%" : "" )}, >+ "extended_attributes.code": extended_attribute_types >+ }); >+ subquery_and.push(sub_or); > }); >+ filters.push({"-and": subquery_and}); > [% END %] > return filters; > } >diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t >index eb2014fd97..cd63599192 100755 >--- a/t/db_dependent/selenium/patrons_search.t >+++ b/t/db_dependent/selenium/patrons_search.t >@@ -51,7 +51,7 @@ my $base_url = $s->base_url; > my $builder = t::lib::TestBuilder->new; > > subtest 'Search patrons' => sub { >- plan tests => 23; >+ plan tests => 24; > > if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { > BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); >@@ -91,6 +91,22 @@ subtest 'Search patrons' => sub { > } > ); > } >+ >+ push @patrons, $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { >+ surname => "test", >+ firstname => "not_p_a_t_r_o_n", # won't match 'patron' >+ categorycode => $patron_category->categorycode, >+ branchcode => $library->branchcode, >+ borrowernotes => $borrowernotes, >+ address => $address, >+ email => $email, >+ } >+ } >+ ); >+ > my $library_2 = $builder->build_object( > { class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } } > ); >@@ -221,6 +237,16 @@ subtest 'Search patrons' => sub { > # And make sure all the patrons are present > is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons), 'Resetting filters works as expected' ); > >+ # Pattern terms must be split >+ $s->fill_form( { search_patron_filter => 'test patron' } ); >+ $s->submit_form; >+ >+ $s->wait_for_ajax; >+ is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons) ); >+ $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); >+ $s->submit_form; >+ $s->wait_for_ajax; >+ > # Search on non-searchable attribute, we expect no result! > $s->fill_form( { search_patron_filter => 'test_attr_1' } ); > $s->submit_form; >-- >2.30.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 30639
:
134251
|
134263
|
134709