Lines 514-532
function patron_autocomplete(node, options) {
Link Here
|
514 |
function buildPatronSearchQuery(term, options) { |
514 |
function buildPatronSearchQuery(term, options) { |
515 |
|
515 |
|
516 |
let q = []; |
516 |
let q = []; |
517 |
let leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; |
517 |
let leading_wildcard; |
518 |
let search_fields = defaultPatronSearchFields; |
518 |
let search_fields; |
|
|
519 |
let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length }); |
520 |
|
521 |
// Bail if no patterns |
522 |
if (patterns.length == 0) { |
523 |
return; |
524 |
} |
525 |
|
526 |
// Leading wildcard: If search_type option exists, we use that |
527 |
if (typeof options !== 'undefined' && options.search_type) { |
528 |
leading_wildcard = options.search_type === "contain" ? '%' : ''; |
529 |
// If not, we use DefaultPatronSearchMethod system preference instead |
530 |
} else { |
531 |
leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; |
532 |
} |
533 |
|
534 |
// Search fields: If search_fields option exists, we use that |
535 |
if (typeof options !== 'undefined' && options.search_fields) { |
536 |
search_fields = options.search_fields; |
537 |
// If not, we use DefaultPatronSearchFields system preference instead |
538 |
} else { |
539 |
search_fields = defaultPatronSearchFields; |
540 |
} |
519 |
|
541 |
|
520 |
// Add each pattern for each search field |
542 |
// Add each pattern for each search field |
521 |
let pattern_subquery_and = []; |
543 |
let pattern_subquery_and = []; |
522 |
term.split(/[\s,]+/) |
544 |
patterns.forEach(function (pattern, i) { |
523 |
.filter(function (s) { return s.length }) |
|
|
524 |
.forEach(function (pattern, i) { |
525 |
let pattern_subquery_or = []; |
545 |
let pattern_subquery_or = []; |
526 |
search_fields.split(',').forEach(function (field, i) { |
546 |
search_fields.split(',').forEach(function (field, i) { |
527 |
pattern_subquery_or.push( |
547 |
pattern_subquery_or.push( |
528 |
{ ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } |
548 |
{ ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } |
529 |
); |
549 |
); |
|
|
550 |
if (field == 'dateofbirth') { |
551 |
try { |
552 |
let d = $date_to_rfc3339(pattern); |
553 |
pattern_subquery_or.push({ ["me." + field]: d }); |
554 |
} catch { |
555 |
// Hide the warning if the date is not correct |
556 |
} |
557 |
} |
530 |
}); |
558 |
}); |
531 |
pattern_subquery_and.push(pattern_subquery_or); |
559 |
pattern_subquery_and.push(pattern_subquery_or); |
532 |
}); |
560 |
}); |
Lines 541-546
function buildPatronSearchQuery(term, options) {
Link Here
|
541 |
}); |
569 |
}); |
542 |
q.push({ "-or": term_subquery_or }); |
570 |
q.push({ "-or": term_subquery_or }); |
543 |
|
571 |
|
544 |
|
572 |
// Add each pattern for each extended patron attributes |
|
|
573 |
if (typeof options !== 'undefined' && options.extended_attribute_types && extendedPatronAttributes) { |
574 |
extended_attribute_subquery_and = []; |
575 |
patterns.forEach(function (pattern, i) { |
576 |
let extended_attribute_sub_or = []; |
577 |
extended_attribute_sub_or.push({ |
578 |
"extended_attributes.value": { "like": leading_wildcard + pattern + '%' }, |
579 |
"extended_attributes.code": extended_attribute_types |
580 |
}); |
581 |
extended_attribute_subquery_and.push(extended_attribute_sub_or); |
582 |
}); |
583 |
q.push({ "-and": extended_attribute_subquery_and }); |
584 |
} |
545 |
return q; |
585 |
return q; |
546 |
} |
586 |
} |
547 |
- |
|
|