@@ -, +, @@ --- .../prog/en/includes/patron-search.inc | 29 ++++++++++++++----- t/db_dependent/selenium/patrons_search.t | 28 +++++++++++++++++- 2 files changed, 49 insertions(+), 8 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ a/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; } --- a/t/db_dependent/selenium/patrons_search.t +++ a/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; --