-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added []api.Fields Generation From Go Struct #183
base: master
Are you sure you want to change the base?
Conversation
nice job! This implementation is better and non-intrusive. |
Thank you, we will be reviewing the PR over the next week! |
Thanks @DawnKosmos, the PR looks good. It seems like we can not set a boolean property to How about we use separate tag for separate property instead of putting them all in one type MyStruct struct {
Name string `json:"id" index:"true" facet:"true"`
UserId string `json:"user_id" join:"user.id"`
} This would also get rid of |
Yes doable, when I have time over the week I change it like this. |
@DawnKosmos Also, could you remove and add that
|
@DawnKosmos coincidentally we had implemented something similar internally at our company. I could contribute some pieces from our implementation if you are willing to accept them. Some of our requirements are/were:
1. Reuse existing structsThis is potentially the controversial one. If you don't want to repeat yourself and have various funcs to convert/marshal from one representation then this should be self explanitory. To avoid conflicts with other libraries (ORMs, validation, openapi, etc), we decided to use a Example struct: type Project struct {
ID uint64 `typesense:"id" json:"id"`
CreatedAt time.Time `typesense:"created_at,sort" json:"created_at"`
UserID uint64 `typesense:"user_id,omitempty" json:"user_id,omitempty"`
Public bool `typesense:"public,facet" json:"-"` // don't return in json, but include in search index
Labels identifier.Tags `typesense:"labels,type=[]string" json:"labels"` // explicitly set search type
Screenshot *storage.File `typesense:"screenshot,omitempty" json:"screenshot,omitempty"` // implict typesense type via interface
} 2. Using an interfaceWe knew our codebase had more complex structs that should be indexed and didn't map directly to the basic typesense primitives. Being the struct authors, we know how the representation should be. In the example above, InterfaceWe created a simple interface that structs can implement and wrapped the typesense client to check if the interface was implemented when generating the schema. If it is, we use use the
|
This PR introduces a new feature for generating Typesense field schemas from Go structs. By analyzing struct tags, this feature automatically constructs a schema that matches the structure and metadata specified in the Go code. This streamlines the process of setting up Typesense collections by reducing the need for manually defining schemas.
Key Features
Usage
PR Checklist