From 2ebacd71ba0231014882b7e1d6d93fdfd89357b1 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 21 Jun 2023 16:10:17 +0000 Subject: [PATCH] Bug 34083: Add searching for full term on patron auto-complete To reproduce, on k-t-d: 1) Create a new patron of category 'School' 2) Enter 'Middle school high school' on the mandatory 'Name' field and put something in 'Card number:' 3) Visit patron lists at /cgi-bin/koha/patron_lists/lists.pl and click 'New patron list' 4) Put something in 'Name:' and click 'Save' 5) On the 'Patron search' input, enter 'middle school high school' slowly and observe the auto-complete behaviour 6) Notice how after you start typing the second word, the auto complete results vanish. 7) Apply patch, repeat plan and verify it now works as expected. --- .../prog/js/patron-autocomplete.js | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js index cc8ec068ae..4222bd9670 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js +++ b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js @@ -15,19 +15,32 @@ function patron_autocomplete(node, options) { } return node.autocomplete({ source: function( request, response ) { - let subquery_and = []; + let q = [] + + // Add each pattern in search term for each search field + let pattern_subquery_and = []; request.term.split(/[\s,]+/) .filter(function(s){ return s.length }) .forEach(function(pattern,i){ - let subquery_or = []; + let pattern_subquery_or = []; defaultPatronSearchFields.split(',').forEach(function(field,i){ - subquery_or.push( + pattern_subquery_or.push( {["me."+field]: {'like': pattern + '%'}} ); }); - subquery_and.push(subquery_or); + pattern_subquery_and.push(pattern_subquery_or); }); - let q = {"-and": subquery_and}; + q.push({ "-and": pattern_subquery_and }); + + // Add full search term for each search field + let term_subquery_or = []; + defaultPatronSearchFields.split(',').forEach(function (field, i) { + term_subquery_or.push( + { ["me." + field]: { 'like': request.term + '%' } } + ); + }); + q.push({ "-or": term_subquery_or }); + let params = { '_page': 1, '_per_page': 10, -- 2.30.2