This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch dev in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git
commit 512bc88a58a181accf0d92f88cfacec4f0d4f8e2 Author: hgaol <[email protected]> AuthorDate: Tue Jan 2 22:13:26 2024 +0800 fix: update algolia search plugin to be compatible with latest search interface (5 days ago) (cherry picked from commit 0c16db54b98f2d156fdc476e12b0f51355453325) --- search-algolia/algolia.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/search-algolia/algolia.go b/search-algolia/algolia.go index 7d4ab3a..49c2ce4 100644 --- a/search-algolia/algolia.go +++ b/search-algolia/algolia.go @@ -72,8 +72,14 @@ func (s *SearchAlgolia) SearchContents(ctx context.Context, cond *plugin.SearchB votesFilter string ) if len(cond.TagIDs) > 0 { - for _, tagID := range cond.TagIDs { - tagFilters = append(tagFilters, "tags:"+tagID) + for _, tagGroup := range cond.TagIDs { + var tagsIn []string + if len(tagGroup) > 0 { + for _, tagID := range tagGroup { + tagsIn = append(tagsIn, "tags:" + tagID) + } + } + tagFilters = append(tagFilters, "(" + strings.Join(tagsIn, " OR ") + ")") } if len(tagFilters) > 0 { filters += " AND " + strings.Join(tagFilters, " AND ") @@ -122,8 +128,14 @@ func (s *SearchAlgolia) SearchQuestions(ctx context.Context, cond *plugin.Search answersFilter string ) if len(cond.TagIDs) > 0 { - for _, tagID := range cond.TagIDs { - tagFilters = append(tagFilters, "tags:"+tagID) + for _, tagGroup := range cond.TagIDs { + var tagsIn []string + if len(tagGroup) > 0 { + for _, tagID := range tagGroup { + tagsIn = append(tagsIn, "tags:" + tagID) + } + } + tagFilters = append(tagFilters, "(" + strings.Join(tagsIn, " OR ") + ")") } if len(tagFilters) > 0 { filters += " AND " + strings.Join(tagFilters, " AND ") @@ -179,8 +191,14 @@ func (s *SearchAlgolia) SearchAnswers(ctx context.Context, cond *plugin.SearchBa questionIDFilter string ) if len(cond.TagIDs) > 0 { - for _, tagID := range cond.TagIDs { - tagFilters = append(tagFilters, "tags:"+tagID) + for _, tagGroup := range cond.TagIDs { + var tagsIn []string + if len(tagGroup) > 0 { + for _, tagID := range tagGroup { + tagsIn = append(tagsIn, "tags:" + tagID) + } + } + tagFilters = append(tagFilters, "(" + strings.Join(tagsIn, " OR ") + ")") } if len(tagFilters) > 0 { filters += " AND " + strings.Join(tagFilters, " AND ")
