Lines 403-409
function patron_autocomplete(node, options) {
Link Here
|
403 |
let link_to; |
403 |
let link_to; |
404 |
let url_params; |
404 |
let url_params; |
405 |
let on_select_callback; |
405 |
let on_select_callback; |
406 |
let leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; |
406 |
|
407 |
if (options) { |
407 |
if (options) { |
408 |
if (options['link-to']) { |
408 |
if (options['link-to']) { |
409 |
link_to = options['link-to']; |
409 |
link_to = options['link-to']; |
Lines 417-447
function patron_autocomplete(node, options) {
Link Here
|
417 |
} |
417 |
} |
418 |
return node.autocomplete({ |
418 |
return node.autocomplete({ |
419 |
source: function (request, response) { |
419 |
source: function (request, response) { |
420 |
let q = [] |
420 |
let q = buildPatronSearchQuery(request.term); |
421 |
|
|
|
422 |
// Add each pattern in search term for each search field |
423 |
let pattern_subquery_and = []; |
424 |
request.term.split(/[\s,]+/) |
425 |
.filter(function (s) { return s.length }) |
426 |
.forEach(function (pattern, i) { |
427 |
let pattern_subquery_or = []; |
428 |
defaultPatronSearchFields.split(',').forEach(function (field, i) { |
429 |
pattern_subquery_or.push( |
430 |
{ ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } |
431 |
); |
432 |
}); |
433 |
pattern_subquery_and.push(pattern_subquery_or); |
434 |
}); |
435 |
q.push({ "-and": pattern_subquery_and }); |
436 |
|
437 |
// Add full search term for each search field |
438 |
let term_subquery_or = []; |
439 |
defaultPatronSearchFields.split(',').forEach(function (field, i) { |
440 |
term_subquery_or.push( |
441 |
{ ["me." + field]: { 'like': leading_wildcard + request.term + '%' } } |
442 |
); |
443 |
}); |
444 |
q.push({ "-or": term_subquery_or }); |
445 |
|
421 |
|
446 |
let params = { |
422 |
let params = { |
447 |
'_page': 1, |
423 |
'_page': 1, |
Lines 533-535
function patron_autocomplete(node, options) {
Link Here
|
533 |
.appendTo(ul); |
509 |
.appendTo(ul); |
534 |
}; |
510 |
}; |
535 |
} |
511 |
} |
536 |
- |
512 |
|
|
|
513 |
|
514 |
function buildPatronSearchQuery(term) { |
515 |
|
516 |
let q = []; |
517 |
let leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; |
518 |
|
519 |
// Add each pattern for each search field |
520 |
let pattern_subquery_and = []; |
521 |
term.split(/[\s,]+/) |
522 |
.filter(function (s) { return s.length }) |
523 |
.forEach(function (pattern, i) { |
524 |
let pattern_subquery_or = []; |
525 |
defaultPatronSearchFields.split(',').forEach(function (field, i) { |
526 |
pattern_subquery_or.push( |
527 |
{ ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } |
528 |
); |
529 |
}); |
530 |
pattern_subquery_and.push(pattern_subquery_or); |
531 |
}); |
532 |
q.push({ "-and": pattern_subquery_and }); |
533 |
|
534 |
// Add full search term for each search field |
535 |
let term_subquery_or = []; |
536 |
defaultPatronSearchFields.split(',').forEach(function (field, i) { |
537 |
term_subquery_or.push( |
538 |
{ ["me." + field]: { 'like': leading_wildcard + term + '%' } } |
539 |
); |
540 |
}); |
541 |
q.push({ "-or": term_subquery_or }); |
542 |
|
543 |
|
544 |
return q; |
545 |
} |