Skip to content

Commit

Permalink
Merge branch 'master' into 181-nil-document-check-on-load
Browse files Browse the repository at this point in the history
  • Loading branch information
Leila-Codes authored Feb 1, 2023
2 parents c77eed5 + c719394 commit 116870d
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ on:
branches:
- master
- '[0-9].[0-9]'
schedule:
- cron: "5 1 * * *"

jobs:

Expand Down
5 changes: 3 additions & 2 deletions examples/redisearch_auth/redisearch_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"fmt"
"github.com/RediSearch/redisearch-go/redisearch"
"github.com/gomodule/redigo/redis"
"log"
"time"

"github.com/RediSearch/redisearch-go/v2/redisearch"
"github.com/gomodule/redigo/redis"
)

// exemplifies the NewClientFromPool function
Expand Down
3 changes: 2 additions & 1 deletion examples/redisearch_geo/redisearch_geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"fmt"
"github.com/RediSearch/redisearch-go/redisearch"
"log"

"github.com/RediSearch/redisearch-go/v2/redisearch"
)

/**
Expand Down
3 changes: 2 additions & 1 deletion examples/redisearch_quickstart/redisearch_quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"fmt"
"github.com/RediSearch/redisearch-go/redisearch"
"log"
"time"

"github.com/RediSearch/redisearch-go/v2/redisearch"
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/RediSearch/redisearch-go/redisearch"
"github.com/RediSearch/redisearch-go/v2/redisearch"
)

/**
Expand Down
5 changes: 3 additions & 2 deletions examples/redisearch_tls_client/redisearch_tls_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"crypto/x509"
"flag"
"fmt"
"github.com/RediSearch/redisearch-go/redisearch"
"github.com/gomodule/redigo/redis"
"io/ioutil"
"log"
"os"
"time"

"github.com/RediSearch/redisearch-go/v2/redisearch"
"github.com/gomodule/redigo/redis"
)

var (
Expand Down
50 changes: 39 additions & 11 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,26 +523,59 @@ func (info *IndexInfo) loadSchema(values []interface{}, options []string) {
}

f := Field{Name: spec[sliceIndex(spec, "identifier")+1]}
switch strings.ToUpper(spec[sliceIndex(spec, "type")+1]) {
switch strings.ToUpper(options[2]) {
case "TAG":
f.Type = TagField
tfOptions := TagFieldOptions{}
tfOptions := TagFieldOptions{
As: options[0],
}
if sliceIndex(options, "NOINDEX") != -1 {
tfOptions.NoIndex = true
}
if sliceIndex(options, "SORTABLE") != -1 {
tfOptions.Sortable = true
}
if sliceIndex(options, "CASESENSITIVE") != -1 {
tfOptions.CaseSensitive = true
}
if wIdx := sliceIndex(options, "SEPARATOR"); wIdx != -1 {
tfOptions.Separator = options[wIdx+1][0]
}
f.Options = tfOptions
f.Sortable = tfOptions.Sortable
case "GEO":
f.Type = GeoField
gfOptions := GeoFieldOptions{
As: options[0],
}
if sliceIndex(options, "NOINDEX") != -1 {
gfOptions.NoIndex = true
}
f.Options = gfOptions
case "NUMERIC":
f.Type = NumericField
nfOptions := NumericFieldOptions{}
nfOptions := NumericFieldOptions{
As: options[0],
}
if sliceIndex(options, "NOINDEX") != -1 {
nfOptions.NoIndex = true
}
if sliceIndex(options, "SORTABLE") != -1 {
nfOptions.Sortable = true
}
f.Options = nfOptions
f.Sortable = nfOptions.Sortable
case "TEXT":
f.Type = TextField
tfOptions := TextFieldOptions{}
tfOptions := TextFieldOptions{
As: options[0],
}
if sliceIndex(options, "NOSTEM") != -1 {
tfOptions.NoStem = true
}
if sliceIndex(options, "NOINDEX") != -1 {
tfOptions.NoIndex = true
}
if sliceIndex(options, "SORTABLE") != -1 {
tfOptions.Sortable = true
}
Expand All @@ -552,6 +585,7 @@ func (info *IndexInfo) loadSchema(values []interface{}, options []string) {
tfOptions.Weight = float32(weight64)
}
f.Options = tfOptions
f.Sortable = tfOptions.Sortable
case "VECTOR":
f.Type = VectorField
f.Options = VectorFieldOptions{}
Expand Down Expand Up @@ -586,14 +620,8 @@ func (i *Client) Info() (*IndexInfo, error) {
switch key {
case "index_options":
indexOptions, _ = redis.Strings(res[ii+1], nil)
case "fields":
case "fields", "attributes":
schemaAttributes, _ = redis.Values(res[ii+1], nil)
case "attributes":
for _, attr := range res[ii+1].([]interface{}) {
l := len(attr.([]interface{}))
schemaAttributes = append(schemaAttributes, attr.([]interface{})[3:l])

}
}
}

Expand Down
17 changes: 12 additions & 5 deletions redisearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ func TestClient_InfoSchemaFields(t *testing.T) {
Options: NumericFieldOptions{
Sortable: false,
NoIndex: false,
As: "",
As: "age",
},
}
assert.True(t, reflect.DeepEqual(expNumericField, info.Schema.Fields[0]))
Expand All @@ -1225,7 +1225,10 @@ func TestClient_InfoFieldsTest(t *testing.T) {
schema := NewSchema(DefaultOptions).
AddField(NewTextFieldOptions("text", TextFieldOptions{Sortable: true, PhoneticMatcher: PhoneticDoubleMetaphoneEnglish})).
AddField(NewGeoField("geo")).
AddField(NewNumericField("numeric"))
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("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
Expand All @@ -1238,8 +1241,12 @@ func TestClient_InfoFieldsTest(t *testing.T) {
assert.Equal(t,
[]Field(
[]Field{
Field{Name: "text", Type: 0, Sortable: false, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: false, NoIndex: false, PhoneticMatcher: "", As: ""}},
Field{Name: "geo", Type: 2, Sortable: false, Options: interface{}(nil)},
Field{Name: "numeric", Type: 1, Sortable: false, Options: NumericFieldOptions{Sortable: false, NoIndex: false, As: ""}}}),
Field{Name: "text", Type: 0, Sortable: true, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: false, NoIndex: false, PhoneticMatcher: "", As: "text"}},
Field{Name: "geo", Type: 2, Sortable: false, Options: GeoFieldOptions{As: "geo", NoIndex: false}},
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)
}
2 changes: 1 addition & 1 deletion redisearch/example_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"time"

"github.com/RediSearch/redisearch-go/redisearch"
"github.com/RediSearch/redisearch-go/v2/redisearch"
"github.com/gomodule/redigo/redis"
)

Expand Down
5 changes: 3 additions & 2 deletions redisearch/example_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package redisearch_test

import (
"fmt"
"github.com/gomodule/redigo/redis"
"log"
"time"

"github.com/RediSearch/redisearch-go/redisearch"
"github.com/gomodule/redigo/redis"

"github.com/RediSearch/redisearch-go/v2/redisearch"
)

// exemplifies the CreateIndex function with a temporary index specification
Expand Down
6 changes: 3 additions & 3 deletions redisearch/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 116870d

Please sign in to comment.