Skip to content

Add an assertion on missing search index when a $search or $vectorSearch pipeline returns an empty result#2841

Merged
GromNaN merged 3 commits intodoctrine:2.13.xfrom
GromNaN:PHPORM-388
Oct 10, 2025
Merged

Add an assertion on missing search index when a $search or $vectorSearch pipeline returns an empty result#2841
GromNaN merged 3 commits intodoctrine:2.13.xfrom
GromNaN:PHPORM-388

Conversation

@GromNaN
Copy link
Copy Markdown
Member

@GromNaN GromNaN commented Sep 30, 2025

Q A
Type feature
BC Break maybe
Fixed issues PHPORM-388

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.

@GromNaN GromNaN requested review from Copilot and jmikola September 30, 2025 12:31
@GromNaN GromNaN added this to the 2.13.0 milestone Sep 30, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SchemaException class 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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@GromNaN GromNaN force-pushed the PHPORM-388 branch 2 times, most recently from 3e029e9 to bd7f87b Compare October 1, 2025 08:12
@GromNaN GromNaN merged commit 3acd6da into doctrine:2.13.x Oct 10, 2025
23 checks passed
@GromNaN GromNaN deleted the PHPORM-388 branch October 10, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants