Skip to content

Commit

Permalink
Added support for MAXTEXTFIELDS on FT.CREATE. (#83)
Browse files Browse the repository at this point in the history
* [add] Added support for MAXTEXTFIELDS on FT.CREATE. Added SetMaxTextFieldsFlag
  • Loading branch information
filipecosta90 authored Aug 18, 2020
1 parent b71ddb1 commit db479df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
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

0 comments on commit db479df

Please sign in to comment.