From 9708884f4911f3d9a176ac5ebdf33287e1098579 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Sat, 8 Aug 2020 22:48:55 +0100 Subject: [PATCH] [add] v1.4 v1.6 and v2.0 working as expected on features present across versions --- redisearch/index.go | 40 +++++++++++++++++------------------ redisearch/redisearch_test.go | 15 ++++++++++--- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/redisearch/index.go b/redisearch/index.go index 9d11566..47c93e9 100644 --- a/redisearch/index.go +++ b/redisearch/index.go @@ -2,6 +2,26 @@ package redisearch import "github.com/gomodule/redigo/redis" +// IndexInfo - Structure showing information about an existing index +type IndexInfo struct { + Schema Schema + Name string `redis:"index_name"` + DocCount uint64 `redis:"num_docs"` + RecordCount uint64 `redis:"num_records"` + TermCount uint64 `redis:"num_terms"` + MaxDocID uint64 `redis:"max_doc_id"` + InvertedIndexSizeMB float64 `redis:"inverted_sz_mb"` + OffsetVectorSizeMB float64 `redis:"offset_vector_sz_mb"` + DocTableSizeMB float64 `redis:"doc_table_size_mb"` + KeyTableSizeMB float64 `redis:"key_table_size_mb"` + RecordsPerDocAvg float64 `redis:"records_per_doc_avg"` + BytesPerRecordAvg float64 `redis:"bytes_per_record_avg"` + OffsetsPerTermAvg float64 `redis:"offsets_per_term_avg"` + OffsetBitsPerTermAvg float64 `redis:"offset_bits_per_record_avg"` + IsIndexing bool `redis:"indexing"` + PercentIndexed float64 `redis:"percent_indexed"` +} + func SerializeIndexingOptions(opts IndexingOptions, args redis.Args) redis.Args { // apply options if opts.NoSave { @@ -26,23 +46,3 @@ func SerializeIndexingOptions(opts IndexingOptions, args redis.Args) redis.Args } return args } - -// IndexInfo - Structure showing information about an existing index -type IndexInfo struct { - Schema Schema - Name string `redis:"index_name"` - DocCount uint64 `redis:"num_docs"` - RecordCount uint64 `redis:"num_records"` - TermCount uint64 `redis:"num_terms"` - MaxDocID uint64 `redis:"max_doc_id"` - InvertedIndexSizeMB float64 `redis:"inverted_sz_mb"` - OffsetVectorSizeMB float64 `redis:"offset_vector_sz_mb"` - DocTableSizeMB float64 `redis:"doc_table_size_mb"` - KeyTableSizeMB float64 `redis:"key_table_size_mb"` - RecordsPerDocAvg float64 `redis:"records_per_doc_avg"` - BytesPerRecordAvg float64 `redis:"bytes_per_record_avg"` - OffsetsPerTermAvg float64 `redis:"offsets_per_term_avg"` - OffsetBitsPerTermAvg float64 `redis:"offset_bits_per_record_avg"` - IsIndexing bool `redis:"indexing"` - PercentIndexed float64 `redis:"percent_indexed"` -} diff --git a/redisearch/redisearch_test.go b/redisearch/redisearch_test.go index 764568d..703d127 100644 --- a/redisearch/redisearch_test.go +++ b/redisearch/redisearch_test.go @@ -95,8 +95,17 @@ func TestClient(t *testing.T) { } } - docs, _, err := c.Search(NewQuery("hello world")) + // Wait for all documents to be indexed + info, _ := c.Info() + for info.IsIndexing { + time.Sleep(time.Second) + info, _ = c.Info() + } + + docs, total, err := c.Search(NewQuery("hello world")) assert.Nil(t, err) + assert.Equal(t, 100, total) + assert.Equal(t, 10, len(docs)) teardown(c) } @@ -364,7 +373,7 @@ func TestDelete(t *testing.T) { // validate that the index is empty info, err = c.Info() assert.Nil(t, err) - if info.IsIndexing == false { + if !info.IsIndexing { assert.Equal(t, uint64(0), info.DocCount) } @@ -377,7 +386,7 @@ func TestDelete(t *testing.T) { // now we should have 1 document (id = doc1) info, err = c.Info() assert.Nil(t, err) - if info.IsIndexing == false { + if !info.IsIndexing { assert.Equal(t, uint64(1), info.DocCount) }