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> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
8fa7773336
commit
b63f6d95f7
|
|
@ -309,8 +309,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";
|
||||
|
|
@ -318,14 +319,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 + "%"}});
|
||||
});
|
||||
[% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %]
|
||||
filters.push({
|
||||
"extended_attributes.value": { "like": "%" + filter + (search_type == "contain" ? "%" : "" )},
|
||||
"extended_attributes.code": extended_attribute_types
|
||||
|
||||
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 %]
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue