diff --git a/om/hash.go b/om/hash.go index 66f59c13..c237db12 100644 --- a/om/hash.go +++ b/om/hash.go @@ -134,6 +134,12 @@ func (r *HashRepository[T]) Remove(ctx context.Context, id string) error { return r.client.Do(ctx, r.client.B().Del().Key(key(r.prefix, id)).Build()).Error() } +// AlterIndex uses FT.ALTER from the RediSearch module to alter index under the name `hashidx:{prefix}` +// You can use the cmdFn parameter to mutate the index alter command. +func (r *HashRepository[T]) AlterIndex(ctx context.Context, cmdFn func(alter FtAlterIndex) rueidis.Completed) error { + return r.client.Do(ctx, cmdFn(r.client.B().FtAlter().Index(r.idx))).Error() +} + // CreateIndex uses FT.CREATE from the RediSearch module to create inverted index under the name `hashidx:{prefix}` // You can use the cmdFn parameter to mutate the index construction command. func (r *HashRepository[T]) CreateIndex(ctx context.Context, cmdFn func(schema FtCreateSchema) rueidis.Completed) error { diff --git a/om/json.go b/om/json.go index 7b828471..0eb01cb7 100644 --- a/om/json.go +++ b/om/json.go @@ -132,6 +132,12 @@ func (r *JSONRepository[T]) Remove(ctx context.Context, id string) error { return r.client.Do(ctx, r.client.B().Del().Key(key(r.prefix, id)).Build()).Error() } +// AlterIndex uses FT.ALTER from the RediSearch module to alter index under the name `jsonidx:{prefix}` +// You can use the cmdFn parameter to mutate the index alter command. +func (r *JSONRepository[T]) AlterIndex(ctx context.Context, cmdFn func(alter FtAlterIndex) rueidis.Completed) error { + return r.client.Do(ctx, cmdFn(r.client.B().FtAlter().Index(r.idx))).Error() +} + // CreateIndex uses FT.CREATE from the RediSearch module to create inverted index under the name `jsonidx:{prefix}` // You can use the cmdFn parameter to mutate the index construction command, // and note that the field name should be specified with JSON path syntax, otherwise the index may not work as expected. diff --git a/om/repo.go b/om/repo.go index 99ef8160..bf149102 100644 --- a/om/repo.go +++ b/om/repo.go @@ -16,6 +16,8 @@ type ( FtSearchIndex = cmds.FtSearchIndex // FtAggregateIndex is the FT.AGGREGATE command builder FtAggregateIndex = cmds.FtAggregateIndex + // FtAlterSchema is the FT.ALTERINDEX command builder + FtAlterIndex = cmds.FtAlterIndex // Arbitrary is alias to cmds.Arbitrary. This allows user build arbitrary command in Repository.CreateIndex Arbitrary = cmds.Arbitrary ) @@ -43,6 +45,7 @@ type Repository[T any] interface { SaveMulti(ctx context.Context, entity ...*T) (errs []error) Remove(ctx context.Context, id string) error CreateIndex(ctx context.Context, cmdFn func(schema FtCreateSchema) rueidis.Completed) error + AlterIndex(ctx context.Context, cmdFn func(alter FtAlterIndex) rueidis.Completed) error DropIndex(ctx context.Context) error IndexName() string }