55	"github.com/stretchr/testify/assert" 
66	"reflect" 
77	"testing" 
8+ 	"time" 
89)
910
1011func  TestNewSchema (t  * testing.T ) {
@@ -22,6 +23,10 @@ func TestNewSchema(t *testing.T) {
2223			Options : Options {Stopwords : []string {"custom" }}}},
2324		{"no-frequencies" , args {Options {NoFrequencies : true }}, & Schema {Fields : []Field {},
2425			Options : Options {NoFrequencies : true }}},
26+ 		{"no-highlights" , args {Options {NoHighlights : true }}, & Schema {Fields : []Field {},
27+ 			Options : Options {NoHighlights : true }}},
28+ 		{"skip-initial-scan" , args {Options {SkipInitialScan : true }}, & Schema {Fields : []Field {},
29+ 			Options : Options {SkipInitialScan : true }}},
2530	}
2631	for  _ , tt  :=  range  tests  {
2732		t .Run (tt .name , func (t  * testing.T ) {
@@ -50,6 +55,10 @@ func TestSerializeSchema(t *testing.T) {
5055		{"default-args-with-different-constructor" , args {NewSchema (* NewOptions ()), redis.Args {}}, redis.Args {"SCHEMA" }, false },
5156		{"temporary" , args {NewSchema (* NewOptions ().SetTemporaryPeriod (60 )), redis.Args {}}, redis.Args {"TEMPORARY" , 60 , "SCHEMA" }, false },
5257		{"no-frequencies" , args {NewSchema (Options {NoFrequencies : true }), redis.Args {}}, redis.Args {"NOFREQS" , "SCHEMA" }, false },
58+ 		{"no-hithlights" , args {NewSchema (Options {NoHighlights : true }), redis.Args {}}, redis.Args {"NOHL" , "SCHEMA" }, false },
59+ 		{"no-hithlights-with-different-consturctor" , args {NewSchema (* NewOptions ().SetNoHighlight (true )), redis.Args {}}, redis.Args {"NOHL" , "SCHEMA" }, false },
60+ 		{"skip-inital-scan" , args {NewSchema (Options {SkipInitialScan : true }), redis.Args {}}, redis.Args {"SKIPINITIALSCAN" , "SCHEMA" }, false },
61+ 		{"skipinitalscan-with-different-consturctor" , args {NewSchema (* NewOptions ().SetSkipInitialScan (true )), redis.Args {}}, redis.Args {"SKIPINITIALSCAN" , "SCHEMA" }, false },
5362		{"no-fields" , args {NewSchema (Options {NoFieldFlags : true }), redis.Args {}}, redis.Args {"NOFIELDS" , "SCHEMA" }, false },
5463		{"custom-stopwords" , args {NewSchema (Options {Stopwords : []string {"custom" }}), redis.Args {}}, redis.Args {"STOPWORDS" , 1 , "custom" , "SCHEMA" }, false },
5564		{"custom-stopwords-with-different-constructor" , args {NewSchema (* NewOptions ().SetStopWords ([]string {"custom" })), redis.Args {}}, redis.Args {"STOPWORDS" , 1 , "custom" , "SCHEMA" }, false },
@@ -112,3 +121,69 @@ func TestSchema_AddField(t *testing.T) {
112121		})
113122	}
114123}
124+ 
125+ func  TestSchema_SkipInitialScan (t  * testing.T ) {
126+ 	c  :=  createClient ("skip-initial-scan-test" )
127+ 	flush (c )
128+ 
129+ 	// check RediSearch version 
130+ 	version , err  :=  c .getRediSearchVersion ()
131+ 	assert .Nil (t , err )
132+ 	// This feature is only available since RediSearch >= v2.0 
133+ 	if  version  <=  10699  {
134+ 		return 
135+ 	}
136+ 
137+ 	vanillaConnection  :=  c .pool .Get ()
138+ 	_ , err  =  vanillaConnection .Do ("HSET" , "create-index-info:doc1" , "name" , "Jon" , "age" , 25 )
139+ 	assert .Nil (t , err )
140+ 
141+ 	q  :=  NewQuery ("@name:Jon" )
142+ 	schema1  :=  NewSchema (DefaultOptions ).AddField (NewTextField ("name" ))
143+ 	schema2  :=  NewSchema (Options {SkipInitialScan : true }).AddField (NewTextField ("name" ))
144+ 	indexDefinition  :=  NewIndexDefinition ()
145+ 
146+ 	c  =  createClient ("skip-initial-scan-test-scan" )
147+ 	c .CreateIndexWithIndexDefinition (schema1 , indexDefinition )
148+ 	assert .Nil (t , err )
149+ 
150+ 	// Wait for all documents to be indexed 
151+ 	info , err  :=  c .Info ()
152+ 	assert .Nil (t , err )
153+ 	for  info .IsIndexing  {
154+ 		time .Sleep (time .Second )
155+ 		info , _  =  c .Info ()
156+ 	}
157+ 
158+ 	_ , total , err  :=  c .Search (q )
159+ 	assert .Nil (t , err )
160+ 	assert .Equal (t , 1 , total )
161+ 
162+ 	c  =  createClient ("skip-initial-scan-test-skip-scan" )
163+ 	c .CreateIndexWithIndexDefinition (schema2 , indexDefinition )
164+ 	assert .Nil (t , err )
165+ 	_ , total , err  =  c .Search (q )
166+ 	assert .Nil (t , err )
167+ 	assert .Equal (t , 0 , total )
168+ }
169+ 
170+ func  TestSchema_SummarizationDisabled (t  * testing.T ) {
171+ 	doc  :=  NewDocument ("TestSchema-doc1" , 1.0 ).Set ("body" , "foo bar" )
172+ 
173+ 	c  :=  createClient ("summarize-disable-no-term-offsets-test" )
174+ 	flush (c )
175+ 	schema  :=  NewSchema (Options {NoOffsetVectors : true }).AddField (NewTextField ("body" ))
176+ 
177+ 	c .CreateIndex (schema )
178+ 	assert .Nil (t , c .IndexOptions (DefaultIndexingOptions , doc ))
179+ 	_ , _ , err  :=  c .Search (NewQuery ("body" ).Summarize ())
180+ 	assert .NotNil (t , err )
181+ 
182+ 	c  =  createClient ("summarize-disable-no-highlights-test" )
183+ 	flush (c )
184+ 	schema  =  NewSchema (Options {NoHighlights : true }).AddField (NewTextField ("body" ))
185+ 	c .CreateIndex (schema )
186+ 	assert .Nil (t , c .IndexOptions (DefaultIndexingOptions , doc ))
187+ 	_ , _ , err  =  c .Search (NewQuery ("body" ).Summarize ())
188+ 	assert .NotNil (t , err )
189+ }
0 commit comments