tuning where preview text starts to include more complete query term highlighting #740
-
|
Question (or possibly feature request if this cannot be done): So the Is there a way to tune the display of the snippet more, so that at least one occurrence of a matching phrase would be displayed? For example: if I'm searching with the query |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Late reply — sorry about that. Snippet generation and display is outside Fuse's scope — Fuse returns match indices, but how you render them is up to you. That said, the For example, you could find the best match range (longest contiguous match) and center your snippet around that: const bestMatch = result.matches[0].indices
.reduce((best, curr) => (curr[1] - curr[0] > best[1] - best[0]) ? curr : best)
const snippetStart = Math.max(0, bestMatch[0] - 40)
const snippetEnd = Math.min(text.length, bestMatch[1] + 40)
const snippet = text.slice(snippetStart, snippetEnd)Also, |
Beta Was this translation helpful? Give feedback.
Late reply — sorry about that.
Snippet generation and display is outside Fuse's scope — Fuse returns match indices, but how you render them is up to you. That said, the
matches[].indicesarray gives you everything you need to build a smarter snippet.For example, you could find the best match range (longest contiguous match) and center your snippet around that:
Also,
minMatchCharLengthcan help filter o…