Inaccurate search results
Closed this issue · 2 comments
Hi! I’m currently having a problem where inaccurate ranges seem to be returned. Consider this code:
const body = `this is the first line
this is the second line`
console.log(match("second line", body, { withRanges: true }))
Its output is the following:
{
match: true,
ranges: [
{ start: 3, stop: 4 },
{ start: 10, stop: 11 },
{ start: 40, stop: 49 }
]
}
However, the range 40-49 is only a part of the string; if you run slice
on the body, it returns "cond line"
.
Is there any reason why a part of what should be a match is getting lost?
Thanks!
@merelinguist Hey 👋 Thanks for raising the issue
This comes from the fuzzy algorithm: it prefers to match first than to wait for all possibilities and pick the best one. This means that second line
will not match second line
but s
will match the s
from is
and e
will match the e
line
.
Until I add a "full-text search" option which would get all scenarii and pick the best one, there's no way to fix it 👍
Okay, thanks for the feedback 👍