Skip to content

Commit 3958984

Browse files
committed
refactor: add clearExistingSynonyms option and its handling in saveSynonyms method
1 parent 14ee0eb commit 3958984

File tree

6 files changed

+130
-2
lines changed

6 files changed

+130
-2
lines changed

algolia/internal/gen/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var options = []Option{
114114
{"enabled", Other, true, ""}, // Used to enable the rule by default
115115

116116
// Personalization
117-
{"enablePersonalization", Search|Settings, false, ""},
117+
{"enablePersonalization", Search | Settings, false, ""},
118118
{"personalizationImpact", Search, 100, ""},
119119
{"userToken", Search, "", ""},
120120
{"enableReRanking", Search | Settings, true, ""},
@@ -155,6 +155,7 @@ var options = []Option{
155155
{"query", Other, "", ""},
156156
{"autoGenerateObjectIDIfNotExist", Other, false, ""},
157157
{"clearExistingRules", Other, false, ""},
158+
{"clearExistingSynonyms", Other, false, ""},
158159
{"replaceExistingSynonyms", Other, false, ""},
159160
{"type", Other, nil, ""},
160161
{"createIfNotExists", Other, true, ""},

algolia/internal/opt/clear_existing_synonyms.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

algolia/internal/opt/clear_existing_synonyms_test.go

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

algolia/opt/clear_existing_synonyms.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

algolia/opt/option_getters_test.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

algolia/search/index_synonyms.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ func (i *Index) SaveSynonym(synonym Synonym, opts ...interface{}) (res UpdateTas
4646
// Unlike SaveObjects, this method does not batch the given synonyms i.e. all synonyms
4747
// are sent in a single call.
4848
func (i *Index) SaveSynonyms(synonyms []Synonym, opts ...interface{}) (res UpdateTaskRes, err error) {
49-
if replaceExistingSynonyms := iopt.ExtractReplaceExistingSynonyms(opts...); replaceExistingSynonyms != nil {
49+
50+
if clearExistingSynonyms := iopt.ExtractClearExistingSynonyms(opts...); clearExistingSynonyms != nil {
51+
opts = opt.InsertExtraURLParam(opts, "replaceExistingSynonyms", clearExistingSynonyms.Get())
52+
} else if replaceExistingSynonyms := iopt.ExtractReplaceExistingSynonyms(opts...); replaceExistingSynonyms != nil {
53+
// if clearExistingSynonyms parameter is missing, attempt to parse legacy replaceExistingSynonyms option
5054
opts = opt.InsertExtraURLParam(opts, "replaceExistingSynonyms", replaceExistingSynonyms.Get())
5155
}
56+
5257
path := i.path("/synonyms/batch")
5358
err = i.transport.Request(&res, http.MethodPost, path, synonyms, call.Write, opts...)
5459
res.wait = i.WaitTask

0 commit comments

Comments
 (0)