Open
Description
Search results are untyped (map[string]any
) which makes this very unergonomic to use
Currently we're working around it with a custom search method
func searchCollection[TDoc any](ctx context.Context, collection string, params *api.SearchCollectionParams) (*Result[TDoc], error) {
resp, err := typesenseApiClient.SearchCollection(ctx, collection, params)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode > 299 {
return nil, utils.ErrHighStatusCode
}
var results Result[TDoc]
err = json.NewDecoder(resp.Body).Decode(&results)
if err != nil {
return nil, err
}
return &results, nil
}
and matching types
type Result[TDoc any] struct {
GroupedHits []GroupedHit[TDoc] `json:"grouped_hits,omitempty"`
Hits []*ResultHit[TDoc] `json:"hits,omitempty"`
...
Metadata
Metadata
Assignees
Labels
No labels