Lines 548-554
function buildPatronSearchQuery(term, options) {
Link Here
|
548 |
|
548 |
|
549 |
let q = []; |
549 |
let q = []; |
550 |
let leading_wildcard; |
550 |
let leading_wildcard; |
551 |
let search_fields; |
551 |
let search_fields = []; |
552 |
let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length }); |
552 |
let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length }); |
553 |
|
553 |
|
554 |
// Bail if no patterns |
554 |
// Bail if no patterns |
Lines 564-572
function buildPatronSearchQuery(term, options) {
Link Here
|
564 |
leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; |
564 |
leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; |
565 |
} |
565 |
} |
566 |
|
566 |
|
|
|
567 |
let searched_attribute_fields = []; |
567 |
// Search fields: If search_fields option exists, we use that |
568 |
// Search fields: If search_fields option exists, we use that |
568 |
if (typeof options !== 'undefined' && options.search_fields) { |
569 |
if (typeof options !== 'undefined' && options.search_fields) { |
569 |
search_fields = expandPatronSearchFields(options.search_fields); |
570 |
expand_fields = expandPatronSearchFields(options.search_fields); |
|
|
571 |
expand_fields.split('\|').forEach(function (field, i) { |
572 |
if( field.startsWith('_ATTR_') ){ |
573 |
let attr_field = field.replace("_ATTR_",""); |
574 |
searched_attribute_fields.push( attr_field ); |
575 |
} else { |
576 |
search_fields.push( field ); |
577 |
} |
578 |
}); |
570 |
// If not, we use DefaultPatronSearchFields system preference instead |
579 |
// If not, we use DefaultPatronSearchFields system preference instead |
571 |
} else { |
580 |
} else { |
572 |
search_fields = defaultPatronSearchFields; |
581 |
search_fields = defaultPatronSearchFields; |
Lines 576-582
function buildPatronSearchQuery(term, options) {
Link Here
|
576 |
let pattern_subquery_and = []; |
585 |
let pattern_subquery_and = []; |
577 |
patterns.forEach(function (pattern, i) { |
586 |
patterns.forEach(function (pattern, i) { |
578 |
let pattern_subquery_or = []; |
587 |
let pattern_subquery_or = []; |
579 |
search_fields.split('|').forEach(function (field, i) { |
588 |
search_fields.forEach(function (field, i) { |
580 |
pattern_subquery_or.push( |
589 |
pattern_subquery_or.push( |
581 |
{ ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } |
590 |
{ ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } |
582 |
); |
591 |
); |
Lines 593-601
function buildPatronSearchQuery(term, options) {
Link Here
|
593 |
}); |
602 |
}); |
594 |
q.push({ "-and": pattern_subquery_and }); |
603 |
q.push({ "-and": pattern_subquery_and }); |
595 |
|
604 |
|
|
|
605 |
|
596 |
// Add full search term for each search field |
606 |
// Add full search term for each search field |
597 |
let term_subquery_or = []; |
607 |
let term_subquery_or = []; |
598 |
search_fields.split('\|').forEach(function (field, i) { |
608 |
search_fields.forEach(function (field, i) { |
599 |
term_subquery_or.push( |
609 |
term_subquery_or.push( |
600 |
{ ["me." + field]: { 'like': leading_wildcard + term + '%' } } |
610 |
{ ["me." + field]: { 'like': leading_wildcard + term + '%' } } |
601 |
); |
611 |
); |
Lines 603-615
function buildPatronSearchQuery(term, options) {
Link Here
|
603 |
q.push({ "-or": term_subquery_or }); |
613 |
q.push({ "-or": term_subquery_or }); |
604 |
|
614 |
|
605 |
// Add each pattern for each extended patron attributes |
615 |
// Add each pattern for each extended patron attributes |
606 |
if (typeof options !== 'undefined' && options.search_fields == 'standard' && options.extended_attribute_types && extendedPatronAttributes) { |
616 |
if ( typeof options !== 'undefined' && ( (options.search_fields == 'standard' && options.extended_attribute_types) || searched_attribute_fields ) && extendedPatronAttributes) { |
|
|
617 |
extended_attribute_codes_to_search = (searched_attribute_fields.length > 0) ? searched_attribute_fields : options.extended_attribute_types; |
607 |
extended_attribute_subquery_and = []; |
618 |
extended_attribute_subquery_and = []; |
608 |
patterns.forEach(function (pattern, i) { |
619 |
patterns.forEach(function (pattern, i) { |
609 |
let extended_attribute_sub_or = []; |
620 |
let extended_attribute_sub_or = []; |
610 |
extended_attribute_sub_or.push({ |
621 |
extended_attribute_sub_or.push({ |
611 |
"extended_attributes.value": { "like": leading_wildcard + pattern + '%' }, |
622 |
"extended_attributes.value": { "like": leading_wildcard + pattern + '%' }, |
612 |
"extended_attributes.code": options.extended_attribute_types |
623 |
"extended_attributes.code": extended_attribute_codes_to_search |
613 |
}); |
624 |
}); |
614 |
extended_attribute_subquery_and.push(extended_attribute_sub_or); |
625 |
extended_attribute_subquery_and.push(extended_attribute_sub_or); |
615 |
}); |
626 |
}); |
616 |
- |
|
|