typesense / typesense/typesense-go

Add support for generics

Open
#144 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
319
Forks
73
PR merge metrics
No merged PRs in 30d

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"`
...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at SearchCollection and the existing Result, GroupedHit, and ResultHit types; compare them with the custom generic implementation shown in the issue. Determine the supported generic search-result API and the affected response shapes. Done means callers can receive typed search results without maintaining a custom search method.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, search
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.