From 9ede2d1165d20f4e132661ecc3841fd3df8f858c Mon Sep 17 00:00:00 2001 From: vatsal Date: Wed, 9 Oct 2024 17:23:29 -0700 Subject: [PATCH 1/2] Add FT.ALTER in OM JSON and Hash repo Signed-off-by: Vatsal --- om/hash.go | 6 ++++++ om/json.go | 6 ++++++ om/repo.go | 3 +++ 3 files changed, 15 insertions(+) diff --git a/om/hash.go b/om/hash.go index 66f59c13..94220bbf 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(schema FtAlterSchema) rueidis.Completed) error { + return r.client.Do(ctx, cmdFn(r.client.B().FtAlter().Index(r.idx).Schema())).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..b24a4cc1 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(schema FtAlterSchema) rueidis.Completed) error { + return r.client.Do(ctx, cmdFn(r.client.B().FtAlter().Index(r.idx).Schema())).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..81a9d658 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 + FtAlterSchema = cmds.FtAlterSchema // 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(schema FtAlterSchema) rueidis.Completed) error DropIndex(ctx context.Context) error IndexName() string } From 93654b65e57e23eece9807640c00fbc99189d69c Mon Sep 17 00:00:00 2001 From: vatsal Date: Thu, 10 Oct 2024 15:50:33 -0700 Subject: [PATCH 2/2] Add FT.ALTER in OM JSON and Hash repo Signed-off-by: Vatsal --- om/hash.go | 4 ++-- om/json.go | 4 ++-- om/repo.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/om/hash.go b/om/hash.go index 94220bbf..c237db12 100644 --- a/om/hash.go +++ b/om/hash.go @@ -136,8 +136,8 @@ func (r *HashRepository[T]) Remove(ctx context.Context, id string) 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(schema FtAlterSchema) rueidis.Completed) error { - return r.client.Do(ctx, cmdFn(r.client.B().FtAlter().Index(r.idx).Schema())).Error() +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}` diff --git a/om/json.go b/om/json.go index b24a4cc1..0eb01cb7 100644 --- a/om/json.go +++ b/om/json.go @@ -134,8 +134,8 @@ func (r *JSONRepository[T]) Remove(ctx context.Context, id string) 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(schema FtAlterSchema) rueidis.Completed) error { - return r.client.Do(ctx, cmdFn(r.client.B().FtAlter().Index(r.idx).Schema())).Error() +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}` diff --git a/om/repo.go b/om/repo.go index 81a9d658..bf149102 100644 --- a/om/repo.go +++ b/om/repo.go @@ -17,7 +17,7 @@ type ( // FtAggregateIndex is the FT.AGGREGATE command builder FtAggregateIndex = cmds.FtAggregateIndex // FtAlterSchema is the FT.ALTERINDEX command builder - FtAlterSchema = cmds.FtAlterSchema + FtAlterIndex = cmds.FtAlterIndex // Arbitrary is alias to cmds.Arbitrary. This allows user build arbitrary command in Repository.CreateIndex Arbitrary = cmds.Arbitrary ) @@ -45,7 +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(schema FtAlterSchema) rueidis.Completed) error + AlterIndex(ctx context.Context, cmdFn func(alter FtAlterIndex) rueidis.Completed) error DropIndex(ctx context.Context) error IndexName() string }