-
Couldn't load subscription status.
- Fork 63
feat: update algolia-search plugin #301
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the Algolia search plugin by migrating from the v3 to v4 version of the algoliasearch-client-go SDK. The migration involves significant API changes requiring adaptations to method calls, data structures, and initialization patterns.
- Updates the Algolia search client SDK from v3 to v4
- Refactors all search and indexing operations to use the new v4 API patterns
- Adds proper JSON marshalling/unmarshalling for data transformation
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| go.mod | Updates dependency from algoliasearch-client-go/v3 to v4 and related version bumps |
| algolia.go | Major refactoring of client initialization, search methods, and CRUD operations for v4 API compatibility |
| initsearch.go | Updates settings initialization and virtual replica configuration to use v4 API patterns |
| sync.go | Refactors batch update operations with JSON marshalling for v4 compatibility |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
search-algolia/algolia.go
Outdated
| res = append(res, plugin.SearchResult{ | ||
| ID: hit["objectID"].(string), | ||
| Type: hit["type"].(string), | ||
| ID: hit.ObjectID, | ||
| Type: "question", |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type is being hardcoded to 'question' instead of using the actual type from the hit. This will cause incorrect type classification for non-question content like answers.
search-algolia/algolia.go
Outdated
| ID: hit["objectID"].(string), | ||
| Type: hit["type"].(string), | ||
| ID: hit.ObjectID, | ||
| Type: "question", |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type is being hardcoded to 'question' instead of using the actual type from the hit. This will cause incorrect type classification for answer content.
| Type: "question", | |
| Type: hit.Type, |
search-algolia/algolia.go
Outdated
| res = append(res, plugin.SearchResult{ | ||
| ID: hit["objectID"].(string), | ||
| Type: hit["type"].(string), | ||
| ID: hit.ObjectID, | ||
| Type: "question", |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type is being hardcoded to 'question' in the SearchAnswers method, but this should reflect the actual content type from the search results.
search-algolia/sync.go
Outdated
| jsonRecords, err := json.Marshal(contents) | ||
| if err != nil { | ||
| return | ||
| } | ||
| err = res.Wait() | ||
| err = json.Unmarshal(jsonRecords, &records) | ||
| if err != nil { | ||
| return | ||
| } |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This marshal-unmarshal pattern is inefficient. Consider using a more direct type conversion or reflection to convert []*plugin.SearchContent to []map[string]any without the JSON roundtrip.
| jsonRecords, err := json.Marshal(contents) | |
| if err != nil { | |
| return | |
| } | |
| err = res.Wait() | |
| err = json.Unmarshal(jsonRecords, &records) | |
| if err != nil { | |
| return | |
| } | |
| for _, content := range contents { | |
| var m map[string]any | |
| b, err := json.Marshal(content) | |
| if err != nil { | |
| return err | |
| } | |
| if err := json.Unmarshal(b, &m); err != nil { | |
| return err | |
| } | |
| records = append(records, m) | |
| } |
search-algolia/algolia.go
Outdated
| j, err := json.Marshal(content) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| err = json.Unmarshal(j, &data) |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This marshal-unmarshal pattern is inefficient. Consider using a more direct type conversion to convert *plugin.SearchContent to map[string]any without the JSON roundtrip.
| SetHitsPerPage(int32(cond.PageSize)), | ||
| ), | ||
| ), | ||
| ) |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error check after the SearchSingleIndex call. The code should verify that err is nil before proceeding to iterate over hits.
| ) | |
| ) | |
| if err != nil { | |
| return nil, 0, err | |
| } |
update algolia search client SDK(algoliasearch-client-go): V3 -> V4