|
660 | 660 | return [];
|
661 | 661 | }
|
662 | 662 | // iterate through search fields looking for matches
|
663 |
| - $.each(searchFields, function (index, field) { |
664 |
| - $.each(source, function (label, content) { |
| 663 | + var lastSearchFieldIndex = searchFields.length - 1; |
| 664 | + $.each(source, function (label, content) { |
| 665 | + var concatenatedContent = []; |
| 666 | + $.each(searchFields, function (index, field) { |
665 | 667 | var
|
666 | 668 | fieldExists = (typeof content[field] === 'string') || (typeof content[field] === 'number')
|
667 | 669 | ;
|
|
670 | 672 | text = typeof content[field] === 'string'
|
671 | 673 | ? module.remove.diacritics(content[field])
|
672 | 674 | : content[field].toString();
|
673 |
| - if (text.search(matchRegExp) !== -1) { |
| 675 | + if (settings.fullTextSearch === 'all') { |
| 676 | + concatenatedContent.push(text); |
| 677 | + if (index < lastSearchFieldIndex) { |
| 678 | + return true; |
| 679 | + } |
| 680 | + text = concatenatedContent.join(' '); |
| 681 | + } |
| 682 | + if (settings.fullTextSearch !== 'all' && text.search(matchRegExp) !== -1) { |
674 | 683 | // content starts with value (first in results)
|
675 | 684 | addResult(results, content);
|
676 | 685 | } else if (settings.fullTextSearch === 'exact' && module.exactSearch(searchTerm, text)) {
|
677 |
| - // content fuzzy matches (last in results) |
| 686 | + addResult(exactResults, content); |
| 687 | + } else if (settings.fullTextSearch === 'some' && module.wordSearch(searchTerm, text)) { |
| 688 | + addResult(exactResults, content); |
| 689 | + } else if (settings.fullTextSearch === 'all' && module.wordSearch(searchTerm, text, true)) { |
678 | 690 | addResult(exactResults, content);
|
679 | 691 | } else if (settings.fullTextSearch === true && module.fuzzySearch(searchTerm, text)) {
|
680 | 692 | // content fuzzy matches (last in results)
|
|
695 | 707 |
|
696 | 708 | return term.indexOf(query) > -1;
|
697 | 709 | },
|
| 710 | + wordSearch: function (query, term, matchAll) { |
| 711 | + var allWords = query.split(/\s+/), |
| 712 | + w, |
| 713 | + wL = allWords.length, |
| 714 | + found = false |
| 715 | + ; |
| 716 | + for (w = 0; w < wL; w++) { |
| 717 | + found = module.exactSearch(allWords[w], term); |
| 718 | + if ((!found && matchAll) || (found && !matchAll)) { |
| 719 | + break; |
| 720 | + } |
| 721 | + } |
| 722 | + |
| 723 | + return found; |
| 724 | + }, |
698 | 725 | fuzzySearch: function (query, term) {
|
699 | 726 | var
|
700 | 727 | termLength = term.length,
|
|
0 commit comments