diff --git a/.circleci/config.yml b/.circleci/config.yml index a76a359..11d2d40 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,7 @@ jobs: build: # test with redisearch:edge docker: - - image: circleci/golang:1.9 + - image: circleci/golang:1.12 - image: redislabs/redisearch:edge working_directory: /go/src/github.com/RediSearch/redisearch-go @@ -57,7 +57,7 @@ jobs: build_nightly: # test nightly with redisearch:edge docker: - - image: circleci/golang:1.9 + - image: circleci/golang:1.12 - image: redislabs/redisearch:edge working_directory: /go/src/github.com/RediSearch/redisearch-go diff --git a/.gitignore b/.gitignore index b8bc9d2..e921495 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ * !/**/ !**/*.go +!**/go.mod +!**/go.sum !.gitignore !.circleci/config.yml !/tests/*.bz2 diff --git a/Makefile b/Makefile index c6fec56..579e2ae 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ # Go parameters -GOCMD=go +GOCMD=GO111MODULE=on go + GOBUILD=$(GOCMD) build GOINSTALL=$(GOCMD) install GOCLEAN=$(GOCMD) clean -GOTEST=$(GOCMD) test +GOTEST=$(GOCMD) test -count=1 GOGET=$(GOCMD) get GOMOD=$(GOCMD) mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a2f9732 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/RediSearch/redisearch-go + +go 1.12 + +require ( + github.com/gomodule/redigo v2.0.0+incompatible + github.com/stretchr/testify v1.6.1 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9285759 --- /dev/null +++ b/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= +github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/redisearch/aggregate_test.go b/redisearch/aggregate_test.go index 278257d..08307e9 100644 --- a/redisearch/aggregate_test.go +++ b/redisearch/aggregate_test.go @@ -5,8 +5,6 @@ import ( "compress/bzip2" "encoding/json" "fmt" - "github.com/gomodule/redigo/redis" - "github.com/stretchr/testify/assert" "log" "math/rand" "os" @@ -14,8 +12,10 @@ import ( "strconv" "strings" "testing" -) + "github.com/gomodule/redigo/redis" + "github.com/stretchr/testify/assert" +) // Game struct which contains a Asin, a Description, a Title, a Price, and a list of categories // a type and a list of social links @@ -30,7 +30,6 @@ type Game struct { Categories []string `json:"categories"` } - func init() { /* load test data */ value, exists := os.LookupEnv("REDISEARCH_RDB_LOADED") @@ -50,7 +49,7 @@ func init() { ndocs := 10000 docs := make([]Document, ndocs) for i := 0; i < ndocs; i++ { - docs[i] = NewDocument(fmt.Sprintf("doc%d", i), 1).Set("foo", "hello world") + docs[i] = NewDocument(fmt.Sprintf("bench.ft.aggregate.doc%d", i), 1).Set("foo", "hello world") } if err := c.IndexOptions(DefaultIndexingOptions, docs...); err != nil { @@ -317,9 +316,9 @@ func TestCursor_Serialize(t *testing.T) { fields fields want redis.Args }{ - {"TestCursor_Serialize_1", fields{1, 0, 0,}, redis.Args{"WITHCURSOR"}}, - {"TestCursor_Serialize_2_MAXIDLE", fields{1, 0, 30000,}, redis.Args{"WITHCURSOR", "MAXIDLE", 30000}}, - {"TestCursor_Serialize_3_COUNT_MAXIDLE", fields{1, 10, 30000,}, redis.Args{"WITHCURSOR", "COUNT", 10, "MAXIDLE", 30000}}, + {"TestCursor_Serialize_1", fields{1, 0, 0}, redis.Args{"WITHCURSOR"}}, + {"TestCursor_Serialize_2_MAXIDLE", fields{1, 0, 30000}, redis.Args{"WITHCURSOR", "MAXIDLE", 30000}}, + {"TestCursor_Serialize_3_COUNT_MAXIDLE", fields{1, 10, 30000}, redis.Args{"WITHCURSOR", "COUNT", 10, "MAXIDLE", 30000}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -352,7 +351,7 @@ func TestGroupBy_AddFields(t *testing.T) { }{ {"TestGroupBy_AddFields_1", fields{[]string{}, nil, nil}, - args{"a",}, + args{"a"}, &GroupBy{[]string{"a"}, nil, nil}, }, } @@ -651,8 +650,8 @@ func TestProcessAggResponse(t *testing.T) { args args want [][]string }{ - {"empty-reply", args{[]interface{}{}}, [][]string{},}, - {"1-element-reply", args{[]interface{}{[]interface{}{"userFullName", "berge, julius", "count", "2783"}}}, [][]string{{"userFullName", "berge, julius", "count", "2783"}},}, + {"empty-reply", args{[]interface{}{}}, [][]string{}}, + {"1-element-reply", args{[]interface{}{[]interface{}{"userFullName", "berge, julius", "count", "2783"}}}, [][]string{{"userFullName", "berge, julius", "count", "2783"}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/redisearch/client.go b/redisearch/client.go index 29411e7..75dd908 100644 --- a/redisearch/client.go +++ b/redisearch/client.go @@ -613,4 +613,4 @@ func (i *Client) AddHash(docId string, score float32, language string, replace b args = args.Add("REPLACE") } return redis.String(conn.Do("FT.ADDHASH", args...)) -} +} \ No newline at end of file diff --git a/redisearch/client_test.go b/redisearch/client_test.go index 5bd68c7..86b4367 100644 --- a/redisearch/client_test.go +++ b/redisearch/client_test.go @@ -9,6 +9,12 @@ import ( "github.com/stretchr/testify/assert" ) +func flush(c *Client) (err error) { + conn := c.pool.Get() + defer conn.Close() + return conn.Send("FLUSHALL") +} + func TestClient_Get(t *testing.T) { c := createClient("test-get") @@ -72,7 +78,6 @@ func TestClient_Get(t *testing.T) { } func TestClient_MultiGet(t *testing.T) { - c := createClient("test-get") c.Drop() @@ -134,9 +139,9 @@ func TestClient_MultiGet(t *testing.T) { } func TestClient_DictAdd(t *testing.T) { - c := createClient("test-get") - _, err := c.pool.Get().Do("FLUSHALL") - assert.Nil(t, err) + c := createClient("TestClient_DictAdd_Index") + // dict tests require flushall + flush(c) type fields struct { pool ConnPool @@ -155,8 +160,8 @@ func TestClient_DictAdd(t *testing.T) { }{ {"empty-error", fields{pool: c.pool, name: c.name}, args{"dict1", []string{}}, 0, true}, {"1-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"}}, 1, false}, - {"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"}}, 0, false}, - {"multi-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"t1", "t2", "t3", "t4", "t5"}}, 5, false}, + {"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1","term1"}}, 1, false}, + {"multi-term", fields{pool: c.pool, name: c.name}, args{"dict-multi-term", []string{"t1", "t2", "t3", "t4", "t5"}}, 5, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -172,15 +177,16 @@ func TestClient_DictAdd(t *testing.T) { if gotNewTerms != tt.wantNewTerms { t.Errorf("DictAdd() gotNewTerms = %v, want %v", gotNewTerms, tt.wantNewTerms) } + i.DictDel(tt.args.dictionaryName, tt.args.terms) }) } } func TestClient_DictDel(t *testing.T) { - c := createClient("test-get") - _, err := c.pool.Get().Do("FLUSHALL") - assert.Nil(t, err) + c := createClient("TestClient_DictDel_Index") + // dict tests require flushall + flush(c) terms := make([]string, 10) for i := 0; i < 10; i++ { @@ -227,15 +233,15 @@ func TestClient_DictDel(t *testing.T) { } func TestClient_DictDump(t *testing.T) { - c := createClient("test-get") - _, err := c.pool.Get().Do("FLUSHALL") - assert.Nil(t, err) + c := createClient("TestClient_DictDump_Index") + // dict tests require flushall + flush(c) terms1 := make([]string, 10) for i := 0; i < 10; i++ { terms1[i] = fmt.Sprintf("term%d", i) } - c.DictAdd("dict1", terms1) + c.DictAdd("dictdump-dict1", terms1) type fields struct { pool ConnPool @@ -252,7 +258,7 @@ func TestClient_DictDump(t *testing.T) { wantErr bool }{ {"empty-error", fields{pool: c.pool, name: c.name}, args{"dontexist"}, []string{}, true}, - {"dict1", fields{pool: c.pool, name: c.name}, args{"dict1"}, terms1, false}, + {"dictdump-dict1", fields{pool: c.pool, name: c.name}, args{"dictdump-dict1"}, terms1, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -381,7 +387,7 @@ func TestClient_AliasUpdate(t *testing.T) { docs := make([]Document, 100) for i := 0; i < 100; i++ { - docs[i] = NewDocument(fmt.Sprintf("doc-alias-del-%d", i), 1).Set("foo", "hello world").Set("bar", "hello world foo bar baz") + docs[i] = NewDocument(fmt.Sprintf("doc-alias-update-%d", i), 1).Set("foo", "hello world").Set("bar", "hello world foo bar baz") } err = c.Index(docs...) @@ -418,7 +424,7 @@ func TestClient_AliasUpdate(t *testing.T) { func TestClient_Config(t *testing.T) { c := createClient("testconfigindex") - + c.Drop() ret, err := c.SetConfig("TIMEOUT", "100") assert.Nil(t, err) assert.Equal(t, "OK", ret) @@ -527,8 +533,12 @@ func TestClient_AddHash(t *testing.T) { c.pool.Get().Do("HMSET", "myhash", "field1", "Hello") ret, err := c.AddHash("myhash", 1, "english", false) - assert.Nil(t, err) - assert.Equal(t, "OK", ret) + // Given that FT.ADDHASH is no longer valid for search2+ we assert it's error + if err != nil { + assert.Equal(t, "ERR unknown command `FT.ADDHASH`, with args beginning with: `testAddHash`, `myhash`, `1`, `LANGUAGE`, `english`, ", err.Error()) + } else { + assert.Equal(t, "OK", ret) + } } func TestClient_AddField(t *testing.T) { diff --git a/redisearch/example_client_test.go b/redisearch/example_client_test.go index 5201282..cc962a4 100644 --- a/redisearch/example_client_test.go +++ b/redisearch/example_client_test.go @@ -4,12 +4,13 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "github.com/RediSearch/redisearch-go/redisearch" - "github.com/gomodule/redigo/redis" "io/ioutil" "log" "os" "time" + + "github.com/RediSearch/redisearch-go/redisearch" + "github.com/gomodule/redigo/redis" ) // exemplifies the NewClient function @@ -33,7 +34,7 @@ func ExampleNewClient() { } // Create a document with an id and given score - doc := redisearch.NewDocument("doc1", 1.0) + doc := redisearch.NewDocument("ExampleNewClient:doc1", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("date", time.Now().Unix()) @@ -49,7 +50,7 @@ func ExampleNewClient() { SetReturnFields("title")) fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err) - // Output: doc1 Hello world 1 + // Output: ExampleNewClient:doc1 Hello world 1 } // exemplifies the NewClientFromPool function @@ -76,7 +77,7 @@ func ExampleNewClientFromPool() { } // Create a document with an id and given score - doc := redisearch.NewDocument("doc1", 1.0) + doc := redisearch.NewDocument("ExampleNewClientFromPool:doc2", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("date", time.Now().Unix()) @@ -92,7 +93,7 @@ func ExampleNewClientFromPool() { SetReturnFields("title")) fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err) - // Output: doc1 Hello world 1 + // Output: ExampleNewClientFromPool:doc2 Hello world 1 } //Example of how to establish an SSL connection from your app to the RedisAI Server @@ -163,7 +164,7 @@ func ExampleNewClientFromPool_ssl() { } // Create a document with an id and given score - doc := redisearch.NewDocument("doc1", 1.0) + doc := redisearch.NewDocument("ExampleNewClientFromPool_ssl:doc3", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("date", time.Now().Unix()) diff --git a/redisearch/example_schema_test.go b/redisearch/example_schema_test.go index 23d0d7a..8dc8753 100644 --- a/redisearch/example_schema_test.go +++ b/redisearch/example_schema_test.go @@ -2,9 +2,10 @@ package redisearch_test import ( "fmt" - "github.com/RediSearch/redisearch-go/redisearch" "log" "time" + + "github.com/RediSearch/redisearch-go/redisearch" ) // exemplifies the CreateIndex function with a temporary index specification @@ -25,7 +26,7 @@ func ExampleCreateIndex_temporary() { } // Create a document with an id and given score - doc := redisearch.NewDocument("doc1", 1.0) + doc := redisearch.NewDocument("ExampleCreateIndex_temporary:doc1", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("date", time.Now().Unix()) @@ -46,6 +47,6 @@ func ExampleCreateIndex_temporary() { // Searching with limit and sorting _, err = c.Info() fmt.Println(err) - // Output: doc1 Hello world 1 + // Output: ExampleCreateIndex_temporary:doc1 Hello world 1 // Unknown Index name } diff --git a/redisearch/query_test.go b/redisearch/query_test.go index e341f30..0a6b15d 100644 --- a/redisearch/query_test.go +++ b/redisearch/query_test.go @@ -1,10 +1,12 @@ package redisearch import ( + "math" "reflect" "testing" "github.com/gomodule/redigo/redis" + "github.com/stretchr/testify/assert" ) func TestPaging_serialize(t *testing.T) { @@ -130,3 +132,36 @@ func TestQuery_serialize(t *testing.T) { }) } } + +func Test_appendNumArgs(t *testing.T) { + type args struct { + num float64 + exclude bool + args redis.Args + } + tests := []struct { + name string + args args + want redis.Args + }{ + {"1 arg", args{ 1.0,false,redis.Args{} }, redis.Args{1.0} }, + {"1 excluded arg", args{ 1.0,true,redis.Args{} }, redis.Args{"(",1.0} }, + {"+inf", args{ math.Inf(1),false,redis.Args{} }, redis.Args{"+inf"} }, + {"+inf", args{ math.Inf(-1),false,redis.Args{} }, redis.Args{"-inf"} }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := appendNumArgs(tt.args.num, tt.args.exclude, tt.args.args); !reflect.DeepEqual(got, tt.want) { + t.Errorf("appendNumArgs() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestQuery_SetInKeys_InFields(t *testing.T) { + q := NewQuery("") + q.SetInKeys("abc") + assert.Equal(t, q.InKeys, []string{"abc"}) + q.SetInFields("field1") + assert.Equal(t, q.InFields, []string{"field1"}) +} diff --git a/redisearch/redisearch_test.go b/redisearch/redisearch_test.go index 760d00b..8223eea 100644 --- a/redisearch/redisearch_test.go +++ b/redisearch/redisearch_test.go @@ -2,12 +2,13 @@ package redisearch import ( "fmt" - "github.com/gomodule/redigo/redis" "log" "os" "testing" "time" + "github.com/gomodule/redigo/redis" + "github.com/stretchr/testify/assert" ) @@ -43,6 +44,7 @@ func createClient(indexName string) *Client { } } + func createAutocompleter(dictName string) *Autocompleter { host, password := getTestConnectionDetails() if password != "" { @@ -68,13 +70,14 @@ func TestClient(t *testing.T) { sc := NewSchema(DefaultOptions). AddField(NewTextField("foo")) c.Drop() + if err := c.CreateIndex(sc); err != nil { t.Fatal(err) } docs := make([]Document, 100) for i := 0; i < 100; i++ { - docs[i] = NewDocument(fmt.Sprintf("doc%d", i), float32(i)/float32(100)).Set("foo", "hello world") + docs[i] = NewDocument(fmt.Sprintf("TestClient-doc%d", i), float32(i)/float32(100)).Set("foo", "hello world") } if err := c.IndexOptions(DefaultIndexingOptions, docs...); err != nil { @@ -109,6 +112,7 @@ func TestInfo(t *testing.T) { AddField(NewTextField("foo")). AddField(NewSortableNumericField("bar")) c.Drop() + assert.Nil(t, c.CreateIndex(sc)) _, err := c.Info() @@ -122,11 +126,12 @@ func TestNumeric(t *testing.T) { AddField(NewTextField("foo")). AddField(NewSortableNumericField("bar")) c.Drop() + assert.Nil(t, c.CreateIndex(sc)) docs := make([]Document, 100) for i := 0; i < 100; i++ { - docs[i] = NewDocument(fmt.Sprintf("doc%d", i), 1).Set("foo", "hello world").Set("bar", i) + docs[i] = NewDocument(fmt.Sprintf("TestNumeric-doc%d", i), 1).Set("foo", "hello world").Set("bar", i) } assert.Nil(t, c.Index(docs...)) @@ -140,9 +145,9 @@ func TestNumeric(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 10, len(docs)) assert.Equal(t, 51, total) - assert.Equal(t, "doc90", docs[0].Id) - assert.Equal(t, "doc89", docs[1].Id) - assert.Equal(t, "doc81", docs[9].Id) + assert.Equal(t, "TestNumeric-doc90", docs[0].Id) + assert.Equal(t, "TestNumeric-doc89", docs[1].Id) + assert.Equal(t, "TestNumeric-doc81", docs[9].Id) docs, total, err = c.Search(NewQuery("hello world @bar:[40 90]"). SetSortBy("bar", true). @@ -150,11 +155,11 @@ func TestNumeric(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 10, len(docs)) assert.Equal(t, 51, total) - assert.Equal(t, "doc40", docs[0].Id) + assert.Equal(t, "TestNumeric-doc40", docs[0].Id) assert.Equal(t, "hello world", docs[0].Properties["foo"]) assert.Nil(t, docs[0].Properties["bar"]) - assert.Equal(t, "doc41", docs[1].Id) - assert.Equal(t, "doc49", docs[9].Id) + assert.Equal(t, "TestNumeric-doc41", docs[1].Id) + assert.Equal(t, "TestNumeric-doc49", docs[9].Id) // Try "Explain" explain, err := c.Explain(NewQuery("hello world @bar:[40 90]")) @@ -177,12 +182,12 @@ func TestNoIndex(t *testing.T) { props["f1"] = "MarkZZ" props["f2"] = "MarkZZ" - err = c.Index(Document{Id: "doc1", Properties: props}) + err = c.Index(Document{Id: "TestNoIndex-doc1", Properties: props}) assert.Nil(t, err) props["f1"] = "MarkAA" props["f2"] = "MarkAA" - err = c.Index(Document{Id: "doc2", Properties: props}) + err = c.Index(Document{Id: "TestNoIndex-doc2", Properties: props}) assert.Nil(t, err) _, total, err := c.Search(NewQuery("@f1:Mark*")) @@ -194,20 +199,21 @@ func TestNoIndex(t *testing.T) { docs, total, err := c.Search(NewQuery("@f2:Mark*").SetSortBy("f1", false)) assert.Equal(t, 2, total) - assert.Equal(t, "doc1", docs[0].Id) + assert.Equal(t, "TestNoIndex-doc1", docs[0].Id) docs, total, err = c.Search(NewQuery("@f2:Mark*").SetSortBy("f1", true)) assert.Equal(t, 2, total) - assert.Equal(t, "doc2", docs[0].Id) + assert.Equal(t, "TestNoIndex-doc2", docs[0].Id) } func TestHighlight(t *testing.T) { c := createClient("testung") + c.Drop() sc := NewSchema(DefaultOptions). AddField(NewTextField("foo")). AddField(NewTextField("bar")) - c.Drop() + assert.Nil(t, c.CreateIndex(sc)) docs := make([]Document, 100) @@ -257,11 +263,12 @@ func TestSummarize(t *testing.T) { AddField(NewTextField("foo")). AddField(NewTextField("bar")) c.Drop() + assert.Nil(t, c.CreateIndex(sc)) docs := make([]Document, 10) for i := 0; i < 10; i++ { - docs[i] = NewDocument(fmt.Sprintf("doc%d", i), 1). + docs[i] = NewDocument(fmt.Sprintf("TestSummarize-doc%d", i), 1). Set("foo", "There are two sub-commands commands used for highlighting. One is HIGHLIGHT which surrounds matching text with an open and/or close tag; and the other is SUMMARIZE which splits a field into contextual fragments surrounding the found terms. It is possible to summarize a field, highlight a field, or perform both actions in the same query.").Set("bar", "hello world foo bar baz") } c.Index(docs...) @@ -295,7 +302,7 @@ func TestSummarize(t *testing.T) { } func TestTags(t *testing.T) { - c := createClient("myIndex") + c := createClient("TestTagsIdx") // Create a schema sc := NewSchema(DefaultOptions). @@ -303,7 +310,6 @@ func TestTags(t *testing.T) { AddField(NewTagFieldOptions("tags", TagFieldOptions{Separator: ';'})). AddField(NewTagField("tags2")) - // Drop an existing index. If the index does not exist an error is returned c.Drop() // Create the index with the given schema @@ -312,7 +318,7 @@ func TestTags(t *testing.T) { } // Create a document with an id and given score - doc := NewDocument("doc1", 1.0) + doc := NewDocument("TestTags-doc1", 1.0) doc.Set("title", "Hello world"). Set("tags", "foo bar;bar,baz; hello world"). Set("tags2", "foo bar;bar,baz; hello world") @@ -344,13 +350,13 @@ func TestTags(t *testing.T) { } func TestDelete(t *testing.T) { - c := createClient("testung") + c := createClient("TestDelete-testung") sc := NewSchema(DefaultOptions). AddField(NewTextField("foo")) err := c.Drop() - assert.Nil(t, err) + assert.Nil(t, c.CreateIndex(sc)) var info *IndexInfo @@ -360,7 +366,7 @@ func TestDelete(t *testing.T) { assert.Nil(t, err) assert.Equal(t, uint64(0), info.DocCount) - doc := NewDocument("doc1", 1.0) + doc := NewDocument("TestDelete-doc1", 1.0) doc.Set("foo", "Hello world") err = c.IndexOptions(DefaultIndexingOptions, doc) @@ -372,7 +378,7 @@ func TestDelete(t *testing.T) { assert.Equal(t, uint64(1), info.DocCount) // delete the document from the index - err = c.Delete("doc1", true) + err = c.Delete("TestDelete-doc1", true) assert.Nil(t, err) // validate that the index is empty again @@ -387,12 +393,13 @@ func TestSpellCheck(t *testing.T) { sc := NewSchema(DefaultOptions). AddField(NewTextField("country")) c.Drop() + assert.Nil(t, c.CreateIndex(sc)) docs := make([]Document, len(countries)) for i := 0; i < len(countries); i++ { - docs[i] = NewDocument(fmt.Sprintf("doc%d", i), 1).Set("country", countries[i]) + docs[i] = NewDocument(fmt.Sprintf("TestSpellCheck-doc%d", i), 1).Set("country", countries[i]) } assert.Nil(t, c.Index(docs...)) @@ -431,12 +438,12 @@ func TestFilter(t *testing.T) { AddField(NewNumericField("age")). AddField(NewGeoFieldOptions("location", GeoFieldOptions{})) - // Drop an existing index. If the index does not exist an error is returned c.Drop() + assert.Nil(t, c.CreateIndex(sc)) // Create a document with an id and given score - doc := NewDocument("doc1", 1.0) + doc := NewDocument("TestFilter-doc1", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("age", 18).