Skip to content

Commit dd5a842

Browse files
Merge branch 'master' into support_return_as
2 parents 65badb8 + e0864a7 commit dd5a842

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- run: make test
6262
- run: make godoc_examples
6363
- run: make coverage
64-
- run: bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-action/master/codecov) -t ${CODECOV_TOKEN}
64+
- run: bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -t ${CODECOV_TOKEN}
6565

6666
build-v16:
6767
docker:

redisearch/client_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,13 +919,63 @@ func TestClient_CreateIndex(t *testing.T) {
919919
_, err = vanillaConnection.Do("HSET", "create-index-info:doc2", "name", "John", "age", 20)
920920
assert.Nil(t, err)
921921

922+
// Wait for all documents to be indexed
923+
info, err := c.Info()
924+
assert.Nil(t, err)
925+
for info.IsIndexing {
926+
time.Sleep(time.Second)
927+
info, _ = c.Info()
928+
}
929+
930+
assert.Equal(t, uint64(2), info.DocCount)
931+
assert.Equal(t, false, info.IsIndexing)
932+
assert.Equal(t, uint64(0), info.HashIndexingFailures)
933+
934+
docs, total, err := c.Search(NewQuery("Jon").SetReturnFields("name"))
935+
assert.Nil(t, err)
936+
// Verify that the we've received 2 documents ( Jon and John )
937+
assert.Equal(t, 2, total)
938+
assert.Equal(t, "Jon", docs[0].Properties["name"])
939+
assert.Equal(t, "John", docs[1].Properties["name"])
940+
}
941+
942+
func TestClient_CreateJsonIndex(t *testing.T) {
943+
c := createClient("create-json-index")
944+
flush(c)
945+
version, _ := c.getRediSearchVersion()
946+
if version < 20200 {
947+
// IndexDefinition is available for RediSearch 2.0+
948+
return
949+
}
950+
951+
// Create a schema
952+
schema := NewSchema(DefaultOptions).
953+
AddField(NewTextFieldOptions("$.name", TextFieldOptions{Sortable: true, PhoneticMatcher: PhoneticDoubleMetaphoneEnglish, As: "name"})).
954+
AddField(NewNumericFieldOptions("$.age", NumericFieldOptions{As: "age"}))
955+
956+
// IndexDefinition is available for RediSearch 2.0+
957+
// In this example we will only index keys started by product:
958+
indexDefinition := NewIndexDefinition().SetIndexOn(JSON).AddPrefix("create-json-index:")
959+
960+
// Add the Index Definition
961+
err := c.CreateIndexWithIndexDefinition(schema, indexDefinition)
962+
assert.Nil(t, err)
963+
964+
// Create docs with a name that has the same phonetic matcher
965+
vanillaConnection := c.pool.Get()
966+
_, err = vanillaConnection.Do("JSON.SET", "create-json-index:doc1", "$", "{\"name\":\"Jon\", \"age\": 25}")
967+
assert.Nil(t, err)
968+
_, err = vanillaConnection.Do("JSON.SET", "create-json-index:doc2", "$", "{\"name\":\"John\", \"age\": 25}")
969+
assert.Nil(t, err)
970+
922971
// Wait for all documents to be indexed
923972
info, err := c.Info()
924973
assert.Nil(t, err)
925974
for info.IsIndexing {
926975
time.Sleep(time.Second)
927976
info, _ = c.Info()
928977
}
978+
929979
assert.Equal(t, uint64(2), info.DocCount)
930980
assert.Equal(t, false, info.IsIndexing)
931981
assert.Equal(t, uint64(0), info.HashIndexingFailures)

0 commit comments

Comments
 (0)