Add an assertion on missing search index when a $search or $vectorSearch pipeline returns an empty result#2841
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to detect and report missing search indexes when Atlas Search aggregations return empty results. The feature helps developers identify when queries fail due to non-existent search indexes rather than actual empty result sets.
- Introduces a new
SchemaExceptionclass for search index validation errors - Adds configuration option to enable/disable search index existence checks (enabled by default)
- Implements automatic validation of search indexes when aggregations return empty results
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/Doctrine/ODM/MongoDB/SchemaException.php | New exception class for search index schema errors |
| lib/Doctrine/ODM/MongoDB/Configuration.php | Configuration methods for controlling search index validation |
| lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php | Core logic to validate search index existence on empty results |
| tests/Doctrine/ODM/MongoDB/Tests/Functional/AtlasSearchTest.php | Test coverage for the new search index validation feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| return $this->rewindable ? new CachingIterator($cursor) : new UnrewindableIterator($cursor); | ||
| $iterator = $this->rewindable ? new CachingIterator($cursor) : new UnrewindableIterator($cursor); |
There was a problem hiding this comment.
Noted that both CachingIterator and UnrewindableIterator rewind the inner iterator upon construction, so it's kosher to immediately call current() in the assertion function; however, you should probably make a note of this.
I think the best way to capture this would be to use union types on the assertion method's signature and add a docblock there that notes the point above.
Otherwise, we could not be certain that an arbitrary Iterator instance would be rewound already and capable of accessing current().
…rch pipeline returns an empty result
3e029e9 to
bd7f87b
Compare
Summary
When performing a search query on a search index that doesn't exist, the aggregation returns no results. This is frustrating for users that will try to optimize the query while the issue is the missing search index.
This PR adds a configuration setting (enabled by default) to check if the search index exists only when performing a search aggregation with no returned results.