You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've observed that Fuse.js highlights substrings of searched keywords. It doesn't make any sense to do so because it leads to false positives and highlights that provide no value for the user.
(I'm on 7.0.0 version - there is no 7.0.0 option in the select menu in issue creator, you should add it)
The Fuse.js version where this bug is happening.
Other (please specify in description)
Is this a regression?
This is a regression bug
Which version did this behavior use to work in?
None
Steps To Reproduce
In the input field type in olympics
In matches array, most of the selected indices refer to substrings of the search keyword.For example, it highlights sets of two letters like ic in the word office because ic also exists in the word olympics.
Expected behavior
It should highlight provided keywords as a whole, not a substrings of them. When searching for olympics it should only highlight the word olympics, not ic in the word office.
I'm still figuring this out, Search like Goliath highlighted is okay, but Philistines, and got random letter, or th, la, etc, is too much highligthing that doesn't give value to research of website browser.
Apologies for the long delay on this. I dug into it. The highlight code was marking every character in the text that appears anywhere in the pattern, not just the ones inside the actual matched window. So for olympics, every o, l, y, m, p, i, c, s anywhere the scan visited got marked. That's why ic highlights inside office: both letters happen to be in the olympics alphabet.
Fix queued for 7.4.0-beta.6: restrict highlights to the actual matched window. For your olympics / olympic medical office repro, the output drops from six entries (with multi-character bleed into "medical" and "office") to two: [0,6] (the olympic match) plus a 1-character residual [8,8]. If you want to drop short residuals like that, set minMatchCharLength: 2.
There's a deeper fix that would remove the residual entirely, but it has perf implications, so for now this should suffice (hopefully).
Reopening to track shipping. Thanks for the clean repro and patience on this one.
Shipped in v7.4.0-beta.6 (npm install fuse.js@beta).
For your olympics / olympic medical office repro the indices output now drops from six entries to two: [0,6] (the real olympic match) and [8,8] (a single-char residual from the algorithm's error-extension). Leaving this open for now in case the [8,8] is worth a deeper fix later. Let me know if it's a problem in practice, or if minMatchCharLength: 2 filters it out enough for your case.
Bonus: the fix is also a perf win. ~15% faster fuzzy search on includeMatches queries, and 2-5% on plain fuzzy search. Removing the inner-loop mask write was a bigger savings than the new post-loop fill costs.
Apologies for the long delay on this. I dug into it. The highlight code was marking every character in the text that appears anywhere in the pattern, not just the ones inside the actual matched window. So for olympics, every o, l, y, m, p, i, c, s anywhere the scan visited got marked. That's why ic highlights inside office: both letters happen to be in the olympics alphabet.
Fix queued for 7.4.0-beta.6: restrict highlights to the actual matched window. For your olympics / olympic medical office repro, the output drops from six entries (with multi-character bleed into "medical" and "office") to two: [0,6] (the olympic match) plus a 1-character residual [8,8]. If you want to drop short residuals like that, set minMatchCharLength: 2.
There's a deeper fix that would remove the residual entirely, but it has perf implications, so for now this should suffice (hopefully).
Reopening to track shipping. Thanks for the clean repro and patience on this one.
this helped though in my part, but unfortunately, all other valid two to three words matching the search are no longer highlighted
function highlightMatches(text, indices) {
if (!indices || !indices.length) return text;
const sortedIndices = [...indices].sort((a, b) => a[0] - b[0]);
let result = '';
let lastIndex = 0; sortedIndices.forEach(([start, end]) => {
const matchText = text.slice(start, end + 1);
const beforeChar = start === 0 ? ' ' : text[start - 1];
const afterChar = end === text.length - 1 ? ' ' : text[end + 1];
if (/\W/.test(beforeChar) && /\W/.test(afterChar)) {
result += text.slice(lastIndex, start);
result += <mark>${matchText}</mark>;
lastIndex = end + 1;
}
});
result += text.slice(lastIndex);
return result;
}/* -------------------------------------------------
INIT
-------------------------------------------------- */
document.addEventListener('DOMContentLoaded', () => {
loadBible();
setupSearchBox();
});
Looked into this. Your filter was working by happy accident. The pre-fix code was returning a bunch of noisy indices, and your filter happened to catch the ones that landed on word boundaries. Some of those were legitimate ("David" matching twice), but they came through the same path as the noise. The fix removed both.
Exact matches still work. Your "Philistines" twice example, or anything where the search term appears as-is. Fuzzy matches don't: the algorithm only tracks one best match position per text, so variants/typos/plurals only get the first occurrence highlighted.
This is a real gap, not something I can patch quickly. Fuse was designed to rank documents and highlight the primary match in each, not find every fuzzy occurrence inside one text.
For your use case I'd split it: use Fuse to rank which verses to show, then a separate pass on each visible verse (regex or substring) to find all whole-word matches for highlighting. Fuse.match() per-word also works if you need fuzzy at the word level.
For next steps, I could add "find all fuzzy match positions within a text" to the roadmap as a feature so it stays tracked. But generally that's a separate thing from this issue, so I'll likely close this one.
Looked into this. Your filter was working by happy accident. The pre-fix code was returning a bunch of noisy indices, and your filter happened to catch the ones that landed on word boundaries. Some of those were legitimate ("David" matching twice), but they came through the same path as the noise. The fix removed both.
Exact matches still work. Your "Philistines" twice example, or anything where the search term appears as-is. Fuzzy matches don't: the algorithm only tracks one best match position per text, so variants/typos/plurals only get the first occurrence highlighted.
This is a real gap, not something I can patch quickly. Fuse was designed to rank documents and highlight the primary match in each, not find every fuzzy occurrence inside one text.
For your use case I'd split it: use Fuse to rank which verses to show, then a separate pass on each visible verse (regex or substring) to find all whole-word matches for highlighting. Fuse.match() per-word also works if you need fuzzy at the word level.
For next steps, I could add "find all fuzzy match positions within a text" to the roadmap as a feature so it stays tracked. But generally that's a separate thing from this issue, so I'll likely close this one.
can't find anything greater than fuse.jz it's beyond amazing for me, God bless you, with this search js.
Activity
github-actions commentedon May 14, 2025
This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days
WorldBibleJournal commentedon May 13, 2026
I'm still figuring this out, Search like Goliath highlighted is okay, but Philistines, and got random letter, or th, la, etc, is too much highligthing that doesn't give value to research of website browser.
krisk commentedon May 14, 2026
Apologies for the long delay on this. I dug into it. The highlight code was marking every character in the text that appears anywhere in the pattern, not just the ones inside the actual matched window. So for
olympics, everyo,l,y,m,p,i,c,sanywhere the scan visited got marked. That's whyichighlights insideoffice: both letters happen to be in theolympicsalphabet.Same bug as #505, #611, #691, and #793.
Fix queued for
7.4.0-beta.6: restrict highlights to the actual matched window. For yourolympics/olympic medical officerepro, the output drops from six entries (with multi-character bleed into "medical" and "office") to two:[0,6](theolympicmatch) plus a 1-character residual[8,8]. If you want to drop short residuals like that, setminMatchCharLength: 2.There's a deeper fix that would remove the residual entirely, but it has perf implications, so for now this should suffice (hopefully).
Reopening to track shipping. Thanks for the clean repro and patience on this one.
krisk commentedon May 14, 2026
Shipped in
v7.4.0-beta.6(npm install fuse.js@beta).For your
olympics/olympic medical officerepro the indices output now drops from six entries to two:[0,6](the realolympicmatch) and[8,8](a single-char residual from the algorithm's error-extension). Leaving this open for now in case the[8,8]is worth a deeper fix later. Let me know if it's a problem in practice, or ifminMatchCharLength: 2filters it out enough for your case.Bonus: the fix is also a perf win. ~15% faster fuzzy search on
includeMatchesqueries, and 2-5% on plain fuzzy search. Removing the inner-loop mask write was a bigger savings than the new post-loop fill costs.WorldBibleJournal commentedon May 14, 2026
this helped though in my part, but unfortunately, all other valid two to three words matching the search are no longer highlighted
function highlightMatches(text, indices) {
if (!indices || !indices.length) return text;
const sortedIndices = [...indices].sort((a, b) => a[0] - b[0]);
let result = '';
let lastIndex = 0; sortedIndices.forEach(([start, end]) => {
const matchText = text.slice(start, end + 1);
const beforeChar = start === 0 ? ' ' : text[start - 1];
const afterChar = end === text.length - 1 ? ' ' : text[end + 1];
if (/\W/.test(beforeChar) && /\W/.test(afterChar)) {
result += text.slice(lastIndex, start);
result +=
<mark>${matchText}</mark>;lastIndex = end + 1;
}
});
result += text.slice(lastIndex);
return result;
}/* -------------------------------------------------
INIT
-------------------------------------------------- */
document.addEventListener('DOMContentLoaded', () => {
loadBible();
setupSearchBox();
});
krisk commentedon May 15, 2026
Ok taking a look!
krisk commentedon May 15, 2026
Looked into this. Your filter was working by happy accident. The pre-fix code was returning a bunch of noisy indices, and your filter happened to catch the ones that landed on word boundaries. Some of those were legitimate ("David" matching twice), but they came through the same path as the noise. The fix removed both.
Exact matches still work. Your "Philistines" twice example, or anything where the search term appears as-is. Fuzzy matches don't: the algorithm only tracks one best match position per text, so variants/typos/plurals only get the first occurrence highlighted.
This is a real gap, not something I can patch quickly. Fuse was designed to rank documents and highlight the primary match in each, not find every fuzzy occurrence inside one text.
For your use case I'd split it: use Fuse to rank which verses to show, then a separate pass on each visible verse (regex or substring) to find all whole-word matches for highlighting.
Fuse.match()per-word also works if you need fuzzy at the word level.For next steps, I could add "find all fuzzy match positions within a text" to the roadmap as a feature so it stays tracked. But generally that's a separate thing from this issue, so I'll likely close this one.
WorldBibleJournal commentedon May 15, 2026
can't find anything greater than fuse.jz it's beyond amazing for me, God bless you, with this search js.
pbelzek-cq commentedon May 20, 2026
Wow, I totally forgot about filing this issue 😅 Thank you very much for taking care of this!
chore(deps): pin the fuse.js differential oracle to 7.1.x in Dependab…