From a8e9b25d8e1a1da19a22f20c3cd74ed8a32e3ffb 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. Signed-off-by: Sam Lau Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- .../prog/js/patron-autocomplete.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js index caed62ba8e..cff6a257fd 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js +++ b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js @@ -16,19 +16,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( - {["me."+field]: {'like': leading_wildcard + pattern + '%'}} + pattern_subquery_or.push( + { ["me." + field]: { 'like': leading_wildcard + 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': leading_wildcard + request.term + '%' } } + ); + }); + q.push({ "-or": term_subquery_or }); + let params = { '_page': 1, '_per_page': 10, -- 2.39.5