Skip to content

Commit 2082c9c

Browse files
authored
Merge 98322ca into 81cf501
2 parents 81cf501 + 98322ca commit 2082c9c

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

redisearch/client.go

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -523,26 +523,59 @@ func (info *IndexInfo) loadSchema(values []interface{}, options []string) {
523523
}
524524

525525
f := Field{Name: spec[sliceIndex(spec, "identifier")+1]}
526-
switch strings.ToUpper(spec[sliceIndex(spec, "type")+1]) {
526+
switch strings.ToUpper(options[2]) {
527527
case "TAG":
528528
f.Type = TagField
529-
tfOptions := TagFieldOptions{}
529+
tfOptions := TagFieldOptions{
530+
As: options[0],
531+
}
532+
if sliceIndex(options, "NOINDEX") != -1 {
533+
tfOptions.NoIndex = true
534+
}
535+
if sliceIndex(options, "SORTABLE") != -1 {
536+
tfOptions.Sortable = true
537+
}
538+
if sliceIndex(options, "CASESENSITIVE") != -1 {
539+
tfOptions.CaseSensitive = true
540+
}
530541
if wIdx := sliceIndex(options, "SEPARATOR"); wIdx != -1 {
531542
tfOptions.Separator = options[wIdx+1][0]
532543
}
533544
f.Options = tfOptions
545+
f.Sortable = tfOptions.Sortable
534546
case "GEO":
535547
f.Type = GeoField
548+
gfOptions := GeoFieldOptions{
549+
As: options[0],
550+
}
551+
if sliceIndex(options, "NOINDEX") != -1 {
552+
gfOptions.NoIndex = true
553+
}
554+
f.Options = gfOptions
536555
case "NUMERIC":
537556
f.Type = NumericField
538-
nfOptions := NumericFieldOptions{}
557+
nfOptions := NumericFieldOptions{
558+
As: options[0],
559+
}
560+
if sliceIndex(options, "NOINDEX") != -1 {
561+
nfOptions.NoIndex = true
562+
}
539563
if sliceIndex(options, "SORTABLE") != -1 {
540564
nfOptions.Sortable = true
541565
}
542566
f.Options = nfOptions
567+
f.Sortable = nfOptions.Sortable
543568
case "TEXT":
544569
f.Type = TextField
545-
tfOptions := TextFieldOptions{}
570+
tfOptions := TextFieldOptions{
571+
As: options[0],
572+
}
573+
if sliceIndex(options, "NOSTEM") != -1 {
574+
tfOptions.NoStem = true
575+
}
576+
if sliceIndex(options, "NOINDEX") != -1 {
577+
tfOptions.NoIndex = true
578+
}
546579
if sliceIndex(options, "SORTABLE") != -1 {
547580
tfOptions.Sortable = true
548581
}
@@ -552,6 +585,7 @@ func (info *IndexInfo) loadSchema(values []interface{}, options []string) {
552585
tfOptions.Weight = float32(weight64)
553586
}
554587
f.Options = tfOptions
588+
f.Sortable = tfOptions.Sortable
555589
case "VECTOR":
556590
f.Type = VectorField
557591
f.Options = VectorFieldOptions{}
@@ -586,14 +620,8 @@ func (i *Client) Info() (*IndexInfo, error) {
586620
switch key {
587621
case "index_options":
588622
indexOptions, _ = redis.Strings(res[ii+1], nil)
589-
case "fields":
623+
case "fields", "attributes":
590624
schemaAttributes, _ = redis.Values(res[ii+1], nil)
591-
case "attributes":
592-
for _, attr := range res[ii+1].([]interface{}) {
593-
l := len(attr.([]interface{}))
594-
schemaAttributes = append(schemaAttributes, attr.([]interface{})[3:l])
595-
596-
}
597625
}
598626
}
599627

redisearch/client_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ func TestClient_InfoSchemaFields(t *testing.T) {
12031203
Options: NumericFieldOptions{
12041204
Sortable: false,
12051205
NoIndex: false,
1206-
As: "",
1206+
As: "age",
12071207
},
12081208
}
12091209
assert.True(t, reflect.DeepEqual(expNumericField, info.Schema.Fields[0]))
@@ -1225,7 +1225,9 @@ func TestClient_InfoFieldsTest(t *testing.T) {
12251225
schema := NewSchema(DefaultOptions).
12261226
AddField(NewTextFieldOptions("text", TextFieldOptions{Sortable: true, PhoneticMatcher: PhoneticDoubleMetaphoneEnglish})).
12271227
AddField(NewGeoField("geo")).
1228-
AddField(NewNumericField("numeric"))
1228+
AddField(NewNumericField("numeric")).
1229+
AddField(NewTextFieldOptions("alias_type", TextFieldOptions{As: "type", Sortable: true, NoIndex: true, NoStem: true})).
1230+
AddField(NewTagFieldOptions("address_city", TagFieldOptions{As: "city"}))
12291231
// In this example we will only index keys started by product:
12301232
indexDefinition := NewIndexDefinition().AddPrefix("ft-info-fields-test:")
12311233
// Add the Index Definition
@@ -1238,8 +1240,11 @@ func TestClient_InfoFieldsTest(t *testing.T) {
12381240
assert.Equal(t,
12391241
[]Field(
12401242
[]Field{
1241-
Field{Name: "text", Type: 0, Sortable: false, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: false, NoIndex: false, PhoneticMatcher: "", As: ""}},
1242-
Field{Name: "geo", Type: 2, Sortable: false, Options: interface{}(nil)},
1243-
Field{Name: "numeric", Type: 1, Sortable: false, Options: NumericFieldOptions{Sortable: false, NoIndex: false, As: ""}}}),
1243+
Field{Name: "text", Type: 0, Sortable: true, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: false, NoIndex: false, PhoneticMatcher: "", As: "text"}},
1244+
Field{Name: "geo", Type: 2, Sortable: false, Options: GeoFieldOptions{As: "geo", NoIndex: false}},
1245+
Field{Name: "numeric", Type: 1, Sortable: false, Options: NumericFieldOptions{Sortable: false, NoIndex: false, As: "numeric"}},
1246+
Field{Name: "alias_type", Type: 0, Sortable: true, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: true, NoIndex: true, PhoneticMatcher: "", As: "type"}},
1247+
Field{Name: "address_city", Type: 3, Sortable: false, Options: TagFieldOptions{Separator: 44, NoIndex: false, Sortable: false, CaseSensitive: false, As: "city"}},
1248+
}),
12441249
info.Schema.Fields)
12451250
}

0 commit comments

Comments
 (0)