Skip to content

Conversation

@kumfo
Copy link
Member

@kumfo kumfo commented Oct 11, 2025

update algolia search client SDK(algoliasearch-client-go): V3 -> V4

@kumfo kumfo requested review from LinkinStars and Copilot and removed request for LinkinStars October 11, 2025 08:22
Copy link

Copilot AI left a 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.

Comment on lines 123 to 141
res = append(res, plugin.SearchResult{
ID: hit["objectID"].(string),
Type: hit["type"].(string),
ID: hit.ObjectID,
Type: "question",
Copy link

Copilot AI Oct 11, 2025

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.

Copilot uses AI. Check for mistakes.
ID: hit["objectID"].(string),
Type: hit["type"].(string),
ID: hit.ObjectID,
Type: "question",
Copy link

Copilot AI Oct 11, 2025

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.

Suggested change
Type: "question",
Type: hit.Type,

Copilot uses AI. Check for mistakes.
Comment on lines 240 to 278
res = append(res, plugin.SearchResult{
ID: hit["objectID"].(string),
Type: hit["type"].(string),
ID: hit.ObjectID,
Type: "question",
Copy link

Copilot AI Oct 11, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 81 to 88
jsonRecords, err := json.Marshal(contents)
if err != nil {
return
}
err = res.Wait()
err = json.Unmarshal(jsonRecords, &records)
if err != nil {
return
}
Copy link

Copilot AI Oct 11, 2025

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
Comment on lines 288 to 293
j, err := json.Marshal(content)
if err != nil {
return
}

err = json.Unmarshal(j, &data)
Copy link

Copilot AI Oct 11, 2025

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.

Copilot uses AI. Check for mistakes.
SetHitsPerPage(int32(cond.PageSize)),
),
),
)
Copy link

Copilot AI Oct 11, 2025

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.

Suggested change
)
)
if err != nil {
return nil, 0, err
}

Copilot uses AI. Check for mistakes.
@kumfo kumfo merged commit d36f5d4 into main Oct 11, 2025
1 check passed
@kumfo kumfo deleted the fix/algolia-search branch October 11, 2025 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant