Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions redisearch/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type Options struct {
// Because such indexes are lightweight, you can create thousands of such indexes without negative performance implications.
Temporary bool
TemporaryPeriod int

// For efficiency, RediSearch encodes indexes differently if they are created with less than 32 text fields.
// If set to true This option forces RediSearch to encode indexes as if there were more than 32 text fields,
// which allows you to add additional fields (beyond 32).
MaxTextFieldsFlag bool
}

func NewOptions() *Options {
Expand Down Expand Up @@ -73,15 +78,24 @@ func (options *Options) SetStopWords(stopwords []string) *Options {
return options
}

// For efficiency, RediSearch encodes indexes differently if they are created with less than 32 text fields.
// If set to true, this flag forces RediSearch to encode indexes as if there were more than 32 text fields,
// which allows you to add additional fields (beyond 32).
func (options *Options) SetMaxTextFieldsFlag(flag bool) *Options {
options.MaxTextFieldsFlag = flag
return options
}

// DefaultOptions represents the default options
var DefaultOptions = Options{
NoSave: false,
NoFieldFlags: false,
NoFrequencies: false,
NoOffsetVectors: false,
Stopwords: nil,
Temporary: false,
TemporaryPeriod: 0,
NoSave: false,
NoFieldFlags: false,
NoFrequencies: false,
NoOffsetVectors: false,
Stopwords: nil,
Temporary: false,
TemporaryPeriod: 0,
MaxTextFieldsFlag: false,
}

const (
Expand Down Expand Up @@ -242,6 +256,9 @@ func (m *Schema) AddField(f Field) *Schema {

func SerializeSchema(s *Schema, args redis.Args) (argsOut redis.Args, err error) {
argsOut = args
if s.Options.MaxTextFieldsFlag {
argsOut = append(argsOut, "MAXTEXTFIELDS")
}
if s.Options.NoOffsetVectors {
argsOut = append(argsOut, "NOOFFSETS")
}
Expand Down
2 changes: 2 additions & 0 deletions redisearch/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func TestSerializeSchema(t *testing.T) {
}{

{"default-args", args{NewSchema(DefaultOptions), redis.Args{}}, redis.Args{"SCHEMA"}, false},
{"maxtextfields", args{NewSchema(Options{MaxTextFieldsFlag: true}), redis.Args{}}, redis.Args{"MAXTEXTFIELDS", "SCHEMA"}, false},
{"maxtextfields-with-different-consturctor", args{NewSchema(*NewOptions().SetMaxTextFieldsFlag(true)), redis.Args{}}, redis.Args{"MAXTEXTFIELDS", "SCHEMA"}, false},
{"default-args-with-different-constructor", args{NewSchema(*NewOptions()), redis.Args{}}, redis.Args{"SCHEMA"}, false},
{"temporary", args{NewSchema(*NewOptions().SetTemporaryPeriod(60)), redis.Args{}}, redis.Args{"TEMPORARY", 60, "SCHEMA"}, false},
{"no-frequencies", args{NewSchema(Options{NoFrequencies: true}), redis.Args{}}, redis.Args{"NOFREQS", "SCHEMA"}, false},
Expand Down