Skip to content

Type mismatch in Highlight and HighlightExtended: missing snippets and indices fields per API docs #129

@rabingaire

Description

@rabingaire

The current type definitions for Highlight and HighlightExtended in document.py:725-750 do not match the Typesense 30.2 API response documented at https://typesense.org/docs/30.2/api/search.html.

Current definitions:

class Highlight(typing.TypedDict):
    matched_tokens: typing.List[str]
    snippet: str       # singular, plain string
    value: str

class HighlightExtended(Highlight):
    field: str

class Hit(...):
    highlights: typing.List[HighlightExtended]
    highlight: typing.Dict[str, Highlight]
    ...

Issues where the shape is wrong for search result on multi-value / array fields (eg string[]):

  • snippet vs snippets: The API returns snippets (a list of strings), not a singular snippet. Neither Highlight nor HighlightExtended declare this field.
  • indices is missing: The API returns an indices field (list of integers) indicating which array element(s) matched. Neither Highlight nor HighlightExtended declare this field.
  • matched_tokens is typed as List[str] but should be List[List[str]]: Each element corresponds to a matched array slot and is itself a list of tokens.
  • value placement: value (the full field value with highlights) appears in the highlight dict entries, but not necessarily in each highlights list item. Having it on Highlight (which is used for both) conflates the two shapes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions