From 81b4eafe4124131d71857027a8b97ef299b61ab3 Mon Sep 17 00:00:00 2001 From: Javad Date: Tue, 30 Jul 2024 10:17:04 +0330 Subject: [PATCH] Fix allow typo tolerance to be disabled for an index --- index_settings_test.go | 28 +++++++++++++++++++++++----- types.go | 2 +- types_easyjson.go | 24 ++++-------------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/index_settings_test.go b/index_settings_test.go index d2e31d0e..218e0320 100644 --- a/index_settings_test.go +++ b/index_settings_test.go @@ -2696,6 +2696,28 @@ func TestIndex_UpdateTypoTolerance(t *testing.T) { }, wantResp: &defaultTypoTolerance, }, + { + name: "TestIndexDisableTypoTolerance", + args: args{ + UID: "indexUID", + client: defaultClient, + request: TypoTolerance{ + Enabled: false, + MinWordSizeForTypos: MinWordSizeForTypos{ + OneTypo: 5, + TwoTypos: 9, + }, + DisableOnWords: []string{}, + DisableOnAttributes: []string{}, + }, + }, + wantTask: &TaskInfo{ + TaskUID: 1, + }, + wantResp: &TypoTolerance{ + Enabled: false, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -2704,16 +2726,12 @@ func TestIndex_UpdateTypoTolerance(t *testing.T) { i := c.Index(tt.args.UID) t.Cleanup(cleanup(c)) - gotResp, err := i.GetTypoTolerance() - require.NoError(t, err) - require.Equal(t, tt.wantResp, gotResp) - gotTask, err := i.UpdateTypoTolerance(&tt.args.request) require.NoError(t, err) require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) - gotResp, err = i.GetTypoTolerance() + gotResp, err := i.GetTypoTolerance() require.NoError(t, err) require.Equal(t, &tt.args.request, gotResp) }) diff --git a/types.go b/types.go index fe7b3a4e..ff96a33a 100644 --- a/types.go +++ b/types.go @@ -57,7 +57,7 @@ type Settings struct { // TypoTolerance is the type that represents the typo tolerance setting in Meilisearch type TypoTolerance struct { - Enabled bool `json:"enabled,omitempty"` + Enabled bool `json:"enabled"` MinWordSizeForTypos MinWordSizeForTypos `json:"minWordSizeForTypos,omitempty"` DisableOnWords []string `json:"disableOnWords,omitempty"` DisableOnAttributes []string `json:"disableOnAttributes,omitempty"` diff --git a/types_easyjson.go b/types_easyjson.go index d7408675..f3af9b77 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -247,30 +247,19 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo2(out *jwriter.Write out.RawByte('{') first := true _ = first - if in.Enabled { + { const prefix string = ",\"enabled\":" - first = false out.RawString(prefix[1:]) out.Bool(bool(in.Enabled)) } if true { const prefix string = ",\"minWordSizeForTypos\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } + out.RawString(prefix) (in.MinWordSizeForTypos).MarshalEasyJSON(out) } if len(in.DisableOnWords) != 0 { const prefix string = ",\"disableOnWords\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } + out.RawString(prefix) { out.RawByte('[') for v3, v4 := range in.DisableOnWords { @@ -284,12 +273,7 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo2(out *jwriter.Write } if len(in.DisableOnAttributes) != 0 { const prefix string = ",\"disableOnAttributes\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } + out.RawString(prefix) { out.RawByte('[') for v5, v6 := range in.DisableOnAttributes {