mirror of
https://github.com/owncloud/ocis.git
synced 2026-10-23 23:29:02 +03:00
Add a CLI-only optimize command that compacts the Bleve search index by merging segments. The command opens the index directly via a new engine factory (NewEngineFromConfig), without requiring the running gRPC service. Key changes per review feedback from jvillafanez: - CLI-only: no gRPC endpoint, no proto changes — admin triggers it directly when disruption is acceptable - Engine factory: extracted engine creation from the gRPC handler into NewEngineFromConfig, reusable by both the service and CLI commands - Optimize() merged into Engine interface: no separate Optimizer interface, non-supporting engines can return an error Signed-off-by: Paul Faure <paul@faure.ca> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Martin <github@diemattels.at>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
|
"github.com/owncloud/ocis/v2/services/search/pkg/config"
|
|
"github.com/owncloud/ocis/v2/services/search/pkg/config/parser"
|
|
"github.com/owncloud/ocis/v2/services/search/pkg/engine"
|
|
)
|
|
|
|
// Optimize is the entrypoint for the optimize command.
|
|
func Optimize(cfg *config.Config) *cli.Command {
|
|
return &cli.Command{
|
|
Name: "optimize",
|
|
Usage: "compact the search index by merging segments, without re-indexing content",
|
|
Category: "index management",
|
|
Before: func(_ *cli.Context) error {
|
|
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
|
},
|
|
Action: func(_ *cli.Context) error {
|
|
eng, closer, err := engine.NewEngineFromConfig(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer closer.Close()
|
|
|
|
fmt.Println("optimizing search index...")
|
|
if err := eng.Optimize(context.Background()); err != nil {
|
|
fmt.Println("failed to optimize index: " + err.Error())
|
|
return err
|
|
}
|
|
fmt.Println("index optimization complete")
|
|
return nil
|
|
},
|
|
}
|
|
}
|