From c719394656791416263f8bddee2165aa01221d83 Mon Sep 17 00:00:00 2001 From: Avital Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Thu, 1 Sep 2022 09:57:49 +0300 Subject: [PATCH] Fixing index creation: CASESENSITIVE preceeds SORTABLE (#173) * Change Tag Field Options Order --- redisearch/client_test.go | 4 +++- redisearch/schema.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/redisearch/client_test.go b/redisearch/client_test.go index e5288f7..2752a54 100644 --- a/redisearch/client_test.go +++ b/redisearch/client_test.go @@ -1227,7 +1227,8 @@ func TestClient_InfoFieldsTest(t *testing.T) { AddField(NewGeoField("geo")). AddField(NewNumericField("numeric")). AddField(NewTextFieldOptions("alias_type", TextFieldOptions{As: "type", Sortable: true, NoIndex: true, NoStem: true})). - AddField(NewTagFieldOptions("address_city", TagFieldOptions{As: "city"})) + AddField(NewTagFieldOptions("address_city", TagFieldOptions{As: "city"})). + AddField(NewTagFieldOptions("type", TagFieldOptions{As: "tag", Sortable: true, CaseSensitive: true, NoIndex: true})) // In this example we will only index keys started by product: indexDefinition := NewIndexDefinition().AddPrefix("ft-info-fields-test:") // Add the Index Definition @@ -1245,6 +1246,7 @@ func TestClient_InfoFieldsTest(t *testing.T) { Field{Name: "numeric", Type: 1, Sortable: false, Options: NumericFieldOptions{Sortable: false, NoIndex: false, As: "numeric"}}, Field{Name: "alias_type", Type: 0, Sortable: true, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: true, NoIndex: true, PhoneticMatcher: "", As: "type"}}, Field{Name: "address_city", Type: 3, Sortable: false, Options: TagFieldOptions{Separator: 44, NoIndex: false, Sortable: false, CaseSensitive: false, As: "city"}}, + Field{Name: "type", Type: 3, Sortable: true, Options: TagFieldOptions{Separator: 44, NoIndex: true, Sortable: true, CaseSensitive: true, As: "tag"}}, }), info.Schema.Fields) } diff --git a/redisearch/schema.go b/redisearch/schema.go index 33f8654..7cc1c3e 100644 --- a/redisearch/schema.go +++ b/redisearch/schema.go @@ -422,15 +422,15 @@ func serializeField(f Field, args redis.Args) (argsOut redis.Args, err error) { if opts.Separator != 0 { argsOut = append(argsOut, "SEPARATOR", fmt.Sprintf("%c", opts.Separator)) } + if opts.CaseSensitive { + argsOut = append(argsOut, "CASESENSITIVE") + } if opts.Sortable { argsOut = append(argsOut, "SORTABLE") } if opts.NoIndex { argsOut = append(argsOut, "NOINDEX") } - if opts.CaseSensitive { - argsOut = append(argsOut, "CASESENSITIVE") - } } case GeoField: argsOut = append(argsOut, f.Name, "GEO")