Skip to content
Discussion options

You must be logged in to vote

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[].indices array 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:

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, minMatchCharLength can help filter o…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by krisk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants