Highlights
Search results can now carry highlighted snippets, and a search can leave large fields out of the answer. Before this release you had to choose one or the other: with PDF text indexed, a full page of hits could exceed the response size limit, and the only workaround (not storing the field) made it impossible to highlight. Now a field can stay out of the answer and still be highlighted. Every new field is optional, so existing searches behave exactly as before.
Added
Query.IncludeFieldsandQuery.ExcludeFieldschoose which document fields come back with each hit. A field left out of the answer is still searchable and still highlighted.Query.Highlightasks for snippets: which fields to highlight, how many words of context to keep around a match (AffixTokens), and how many snippets to keep per array field (MaxSnippetsPerArray).SearchResult.Hitslists one entry per returned id, in the same order asIDs. Each hit carries its snippets as segments of plain stored text, each one marked as a match or not. Snippets are never HTML, so stored text containing<or&comes back unchanged and you escape it when rendering.beachcomber.SupportsHighlights(engine)reports whether an engine returns highlights. It is true for Typesense and false for the null engine and for engines that don't implement the new optionalHighlightSearcherinterface, so an app can fall back to its own snippets.- The Typesense engine reads highlights for plain and array fields.
Changed
SearchPagenow always fillsHits, with one empty entry per id when an engine returns no highlights. Code that compares a wholeSearchResultwill see the new field.
Highlights belong to search candidates, not to final answers. Drop the hit of any id that fails your database permission check before you show its snippet, otherwise a snippet can reveal a private document. The search docs have an example.