Skip to content

Commit

Permalink
skip permuting > 5 terms (120 searches) when outOfOrder. close leeoni…
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed Sep 29, 2023
1 parent e823078 commit b4ba3c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dist/uFuzzy.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ function uFuzzy(opts) {
preFiltered = filter(haystack, terms2[ti], preFiltered);
}

// avoid combinatorial explosion by limiting outOfOrder to 5 terms (120 max searches)
// fall back to just filter() otherwise
if (terms.length > 5)
return [preFiltered, null, null];

needles = permute(terms).map(perm => perm.join(' '));

// filtered matches for each needle excluding same matches for prior needles
Expand Down
5 changes: 5 additions & 0 deletions dist/uFuzzy.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,11 @@ function uFuzzy(opts) {
preFiltered = filter(haystack, terms2[ti], preFiltered);
}

// avoid combinatorial explosion by limiting outOfOrder to 5 terms (120 max searches)
// fall back to just filter() otherwise
if (terms.length > 5)
return [preFiltered, null, null];

needles = permute(terms).map(perm => perm.join(' '));

// filtered matches for each needle excluding same matches for prior needles
Expand Down
5 changes: 5 additions & 0 deletions dist/uFuzzy.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,11 @@ var uFuzzy = (function () {
preFiltered = filter(haystack, terms2[ti], preFiltered);
}

// avoid combinatorial explosion by limiting outOfOrder to 5 terms (120 max searches)
// fall back to just filter() otherwise
if (terms.length > 5)
return [preFiltered, null, null];

needles = permute(terms).map(perm => perm.join(' '));

// filtered matches for each needle excluding same matches for prior needles
Expand Down
2 changes: 1 addition & 1 deletion dist/uFuzzy.iife.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/uFuzzy.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,11 @@ export default function uFuzzy(opts) {
preFiltered = filter(haystack, terms2[ti], preFiltered);
}

// avoid combinatorial explosion by limiting outOfOrder to 5 terms (120 max searches)
// fall back to just filter() otherwise
if (terms.length > 5)
return [preFiltered, null, null];

needles = permute(terms).map(perm => perm.join(' '));

// filtered matches for each needle excluding same matches for prior needles
Expand Down

0 comments on commit b4ba3c4

Please sign in to comment.