Skip to content

fix(search): use MustNot query for Deleted filter in bleve#3038

Open
flash7777 wants to merge 1 commit into
opencloud-eu:mainfrom
flash7777:fix/bleve-deleted-query
Open

fix(search): use MustNot query for Deleted filter in bleve#3038
flash7777 wants to merge 1 commit into
opencloud-eu:mainfrom
flash7777:fix/bleve-deleted-query

Conversation

@flash7777

Copy link
Copy Markdown

Summary

The search service uses a BoolFieldQuery{Bool: false, Field: "Deleted"} to exclude trashed documents from results. However, bleve does not index zero-value bools by default. This means documents where Deleted was never explicitly set (i.e., all non-trashed documents) lack this field in the index and are excluded from every query.

Impact: After an index rebuild or on fresh installations, search returns 0 results for all queries.

Root cause

When a Resource is indexed with Deleted: false (Go zero value), bleve's default mapping does not store the bool field. The existing BoolFieldQuery{Bool: false} then finds no matching documents, causing the conjunction query to return empty results.

Fix

Replace BoolFieldQuery{Bool: false} with a BooleanQuery.MustNot(BoolFieldQuery{Bool: true}). This correctly:

  • Includes documents where Deleted is absent (never set)
  • Includes documents where Deleted is explicitly false
  • Excludes only documents where Deleted is explicitly true

Test plan

  • Reproduced: deleted bleve index, rebuilt from scratch, confirmed 0 search results
  • Applied fix, confirmed search returns results after rebuild
  • Verified trashed documents are still excluded (MustNot semantics)

Changes

services/search/pkg/bleve/backend.go: 1 file, +11/-5

BoolFieldQuery{Bool: false, Field: "Deleted"} does not match documents
where the Deleted field was never explicitly set. Bleve does not index
zero-value bools by default, so after an index rebuild (or on fresh
installations), all new documents lack an indexed Deleted field and are
excluded from every search query, resulting in 0 results.

Switch to a BooleanQuery with MustNot(Deleted==true), which correctly
includes all documents where Deleted is absent or false, and only
excludes documents explicitly marked as deleted.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

1 participant