Skip to content

Add support for generics #144

Open
Open
@Hades32

Description

@Hades32

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

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