Skip to content

Commit e8c5bd4

Browse files
support NOHL and SKIPINITIALSCAN tags on FT.CREATE
1 parent 01dd6bf commit e8c5bd4

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

redisearch/schema.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Options struct {
2828
// This is an option that is applied and index level.
2929
NoFrequencies bool
3030

31-
// If set, , we avoid saving the term offsets for documents.
31+
// If set, we avoid saving the term offsets for documents.
3232
// This saves memory but does not allow exact searches or highlighting. Implies NOHL
3333
// This is an option that is applied and index level.
3434
NoOffsetVectors bool
@@ -49,6 +49,13 @@ type Options struct {
4949
// If set to true This option forces RediSearch to encode indexes as if there were more than 32 text fields,
5050
// which allows you to add additional fields (beyond 32).
5151
MaxTextFieldsFlag bool
52+
53+
// If set to true, conserves storage space and memory by disabling highlighting support.
54+
// Also implied by NoOffsetVectors
55+
NoHighlights bool
56+
57+
// If set to true, we do not scan and index.
58+
SkipInitialScan bool
5259
}
5360

5461
func NewOptions() *Options {
@@ -89,6 +96,18 @@ func (options *Options) SetMaxTextFieldsFlag(flag bool) *Options {
8996
return options
9097
}
9198

99+
// SetNoHighlight conserves storage space and memory by disabling highlighting support.
100+
func (options *Options) SetNoHighlight(flag bool) *Options {
101+
options.NoHighlights = flag
102+
return options
103+
}
104+
105+
// SetSkipInitialScan determines if scan the index on creation
106+
func (options *Options) SetSkipInitialScan(flag bool) *Options {
107+
options.SkipInitialScan = flag
108+
return options
109+
}
110+
92111
// DefaultOptions represents the default options
93112
var DefaultOptions = Options{
94113
NoSave: false,
@@ -99,6 +118,8 @@ var DefaultOptions = Options{
99118
Temporary: false,
100119
TemporaryPeriod: 0,
101120
MaxTextFieldsFlag: false,
121+
NoHighlights: false,
122+
SkipInitialScan: false,
102123
}
103124

104125
// Field Types
@@ -282,12 +303,18 @@ func SerializeSchema(s *Schema, args redis.Args) (argsOut redis.Args, err error)
282303
if s.Options.Temporary {
283304
argsOut = append(argsOut, "TEMPORARY", s.Options.TemporaryPeriod)
284305
}
306+
if s.Options.NoHighlights {
307+
argsOut = append(argsOut, "NOHL")
308+
}
285309
if s.Options.NoFieldFlags {
286310
argsOut = append(argsOut, "NOFIELDS")
287311
}
288312
if s.Options.NoFrequencies {
289313
argsOut = append(argsOut, "NOFREQS")
290314
}
315+
if s.Options.SkipInitialScan {
316+
argsOut = append(argsOut, "SKIPINITIALSCAN")
317+
}
291318

292319
if s.Options.Stopwords != nil {
293320
argsOut = argsOut.Add("STOPWORDS", len(s.Options.Stopwords))

redisearch/schema_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func TestNewSchema(t *testing.T) {
2222
Options: Options{Stopwords: []string{"custom"}}}},
2323
{"no-frequencies", args{Options{NoFrequencies: true}}, &Schema{Fields: []Field{},
2424
Options: Options{NoFrequencies: true}}},
25+
{"no-highlights", args{Options{NoHighlights: true}}, &Schema{Fields: []Field{},
26+
Options: Options{NoHighlights: true}}},
27+
{"skip-initial-scan", args{Options{SkipInitialScan: true}}, &Schema{Fields: []Field{},
28+
Options: Options{SkipInitialScan: true}}},
2529
}
2630
for _, tt := range tests {
2731
t.Run(tt.name, func(t *testing.T) {
@@ -50,6 +54,10 @@ func TestSerializeSchema(t *testing.T) {
5054
{"default-args-with-different-constructor", args{NewSchema(*NewOptions()), redis.Args{}}, redis.Args{"SCHEMA"}, false},
5155
{"temporary", args{NewSchema(*NewOptions().SetTemporaryPeriod(60)), redis.Args{}}, redis.Args{"TEMPORARY", 60, "SCHEMA"}, false},
5256
{"no-frequencies", args{NewSchema(Options{NoFrequencies: true}), redis.Args{}}, redis.Args{"NOFREQS", "SCHEMA"}, false},
57+
{"no-hithlights", args{NewSchema(Options{NoHighlights: true}), redis.Args{}}, redis.Args{"NOHL", "SCHEMA"}, false},
58+
{"no-hithlights-with-different-consturctor", args{NewSchema(*NewOptions().SetNoHighlight(true)), redis.Args{}}, redis.Args{"NOHL", "SCHEMA"}, false},
59+
{"skip-inital-scan", args{NewSchema(Options{SkipInitialScan: true}), redis.Args{}}, redis.Args{"SKIPINITIALSCAN", "SCHEMA"}, false},
60+
{"skipinitalscan-with-different-consturctor", args{NewSchema(*NewOptions().SetSkipInitialScan(true)), redis.Args{}}, redis.Args{"SKIPINITIALSCAN", "SCHEMA"}, false},
5361
{"no-fields", args{NewSchema(Options{NoFieldFlags: true}), redis.Args{}}, redis.Args{"NOFIELDS", "SCHEMA"}, false},
5462
{"custom-stopwords", args{NewSchema(Options{Stopwords: []string{"custom"}}), redis.Args{}}, redis.Args{"STOPWORDS", 1, "custom", "SCHEMA"}, false},
5563
{"custom-stopwords-with-different-constructor", args{NewSchema(*NewOptions().SetStopWords([]string{"custom"})), redis.Args{}}, redis.Args{"STOPWORDS", 1, "custom", "SCHEMA"}, false},

0 commit comments

Comments
 (0)