diff --git a/redisearch/document.go b/redisearch/document.go index c45e461..d3d2d9a 100644 --- a/redisearch/document.go +++ b/redisearch/document.go @@ -17,6 +17,7 @@ type Document struct { Id string Score float32 Payload []byte + TTL int Properties map[string]interface{} } @@ -70,6 +71,12 @@ func (d Document) Set(name string, value interface{}) Document { return d } +// SetTTL sets the ttl in the document +func (d Document) SetTTL(ttl int) Document { + d.TTL = ttl + return d +} + // All punctuation marks and whitespaces (besides underscores) separate the document and queries into tokens. // e.g. any character of `,.<>{}[]"':;!@#$%^&*()-+=~` will break the text into terms. // So the text `foo-bar.baz...bag` will be tokenized into `[foo, bar, baz, bag]` diff --git a/redisearch/query.go b/redisearch/query.go index 7113ab6..111c418 100644 --- a/redisearch/query.go +++ b/redisearch/query.go @@ -445,6 +445,18 @@ func (i *Client) IndexOptions(opts IndexingOptions, docs ...Document) error { return merr } + if doc.TTL > 0 { + argsttl := make(redis.Args, 0, 2) + argsttl = append(argsttl, doc.Id, doc.TTL) + if err := conn.Send("EXPIRE", argsttl...); err != nil { + if merr == nil { + merr = NewMultiError(len(docs)) + } + merr[ii] = err + + return merr + } + } n++ }