Home > Software engineering >  How do I use the snippet() function using a FTS5 virtual table in SQLite?
How do I use the snippet() function using a FTS5 virtual table in SQLite?

Time:07-16

In the SQLite documentation for FTS5 it is claimed that 5 parameters must be passed to the snippet function:

The snippet() function is similar to highlight(), except that instead of returning entire column values, it automatically selects and extracts a short fragment of document text to process and return. The snippet() function must be passed five parameters following the table name argument:

  1. An integer indicating the index of the FTS table column to select the returned text from. Columns are numbered from left to right starting at zero. A negative value indicates that the column should be automatically selected.
  2. The text to insert before each phrase match within the returned text.
  3. The text to insert after each phrase match within the returned text.
  4. The text to add to the start or end of the selected text to indicate that the returned text does not occur at the start or end of its column, respectively.
  5. The maximum number of tokens in the returned text. This must be greater than zero and equal to or less than 64.

I've tried this and it does not work:

snippet(1, '<b>', '</b>', '...', 8)

How can I use the snippet() function with a FTS5 virtual table in SQLite?

CodePudding user response:

What I failed to understand was that I also need to pass the table name as the first parameter, like this:

snippet(versesfts, 1, '<b>', '</b>', '...', 8) 

Hopefully this will save someone a couple of hours.

  • Related