Skip to content

feat(search): add ocis search optimize CLI command#12136

Open
paul43210 wants to merge 3 commits intoowncloud:masterfrom
paul43210:feat/search-optimize-command
Open

feat(search): add ocis search optimize CLI command#12136
paul43210 wants to merge 3 commits intoowncloud:masterfrom
paul43210:feat/search-optimize-command

Conversation

@paul43210
Copy link
Contributor

Summary

  • Adds a new ocis search optimize CLI command that compacts the Bleve search index by merging segments (ForceMerge), improving query performance without re-indexing content
  • The command sends a gRPC call to the running search service rather than opening the index directly, since Bleve does not support concurrent access from multiple processes
  • Uses google.protobuf.Empty for the OptimizeIndex RPC to avoid creating new message types

Background

After bulk re-indexing (e.g. ocis search index), the Bleve index can accumulate many small segments that degrade query performance. Currently the only way to compact them is programmatically via the ForceMerge API added in #12104. This PR exposes that capability as a simple CLI command so administrators can trigger optimization on demand.

Requested by @mklos-kw in the context of #12104.

Changes

File What
search.proto Add OptimizeIndex RPC (Empty → Empty)
search.pb.micro.go Generated go-micro client/handler for OptimizeIndex
search.pb.web.go Generated web handler for OptimizeIndex
service.go (search) Add OptimizeIndex to Searcher interface + implementation
service.go (grpc) gRPC handler delegates to Searcher.OptimizeIndex
optimize.go New CLI command — connects to running service, calls OptimizeIndex with 10-min timeout
root.go Register Optimize in command list
mocks/ Updated mockery mocks for new interface method
changelog/ Enhancement changelog entry

Usage

ocis search optimize
# Output: index optimization complete

Test plan

  • make -C services/search test — all 35 tests pass
  • Live-tested on production server: command connects to running search service, triggers ForceMerge, logs show full lifecycle (requested → optimizing → complete), returns in ~31ms on already-compacted index

🤖 Generated with Claude Code

@mmattel mmattel requested review from kobergj and mklos-kw March 22, 2026 16:40
@sonarqubecloud
Copy link

paul43210 and others added 3 commits March 25, 2026 15:55
Add a standalone command to compact the search index by merging bleve
segments without re-indexing content. This is useful for existing
instances where the index has accumulated many small segments from
incremental writes.

The command sends an OptimizeIndex gRPC call to the running search
service, which triggers bleve's ForceMerge. Previously, optimization
only ran at the end of `ocis search index`, requiring a full space
walk even when the index was already up to date.

Usage: ocis search optimize

Proto changes use google.protobuf.Empty for request/response types.
Generated files were hand-edited to match — regenerate with buf if
needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move emptypb import to sort alphabetically with other google.golang.org
imports, fixing SonarCloud gofmt violation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix changelog reference PR number
@mmattel mmattel force-pushed the feat/search-optimize-command branch from 577b800 to 8658473 Compare March 25, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants