← All changes

SummerCMS 0.6.4

v0.6.42 min readFramework

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.IncludeFields and Query.ExcludeFields choose which document fields come back with each hit. A field left out of the answer is still searchable and still highlighted.
  • Query.Highlight asks 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.Hits lists one entry per returned id, in the same order as IDs. 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 optional HighlightSearcher interface, so an app can fall back to its own snippets.
  • The Typesense engine reads highlights for plain and array fields.

Changed

  • SearchPage now always fills Hits, with one empty entry per id when an engine returns no highlights. Code that compares a whole SearchResult will 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.

Subscribe via RSS