Skip to content

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Sep 24, 2025

Q A
Type feature
BC Break maybe
Fixed issues PHPORM-391 PHPORM-392

Summary

Map field names in search and vector search index definitions. Since the $search and $vectorSearch stages must always be first, we know there is no field name mapped from a previous stage.

@GromNaN GromNaN force-pushed the PHPORM-391 branch 2 times, most recently from b844e6e to bb9f3f2 Compare September 26, 2025 02:14
@GromNaN GromNaN marked this pull request as ready for review September 26, 2025 13:06
@GromNaN GromNaN requested a review from Copilot September 26, 2025 13:06
Copy link

@Copilot 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 introduces field name mapping support for MongoDB search and vector search indexes, ensuring that field references in index definitions are properly mapped to their database counterparts when they differ from property names in the ODM.

  • Adds a prepareSearchIndexes method in SchemaManager to map field names in search index definitions
  • Updates search and vector search stages to prepare field paths using the document persister
  • Enhances test coverage to verify field name mapping functionality

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/Doctrine/ODM/MongoDB/SchemaManager.php Adds field name preparation for search indexes
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/VectorSearch.php Updates to prepare field paths in vector search
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search.php Updates to prepare field paths and sort fields in search
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/AbstractSearchOperator.php Adds base field path preparation functionality
lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php Updates to pass document persister to search stages
tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php Adds comprehensive tests for field name mapping
tests/Documents/CmsArticle.php Test document with mapped field names
tests/Documents/VectorEmbedding.php Test document with vector field mapping

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@GromNaN GromNaN added this to the 2.13.0 milestone Sep 26, 2025
@GromNaN GromNaN requested review from jmikola and alcaeus September 26, 2025 14:00
'createOperator' => static function (Search|CompoundSearchOperatorInterface|SupportsEmbeddableSearchOperators $stage) {
return $stage->moreLikeThis(['disabledAt' => new DateTime('2020-01-01T00:00:00Z')]);
},
'className' => User::class,
Copy link
Member Author

@GromNaN GromNaN Sep 26, 2025

Choose a reason for hiding this comment

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

Switching to an other document class to validate transformation of the date value.

public function autocomplete(string $path = '', string ...$query): Autocomplete&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedAutocomplete($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path, ...$query));
return $this->addOperator(new CompoundedAutocomplete($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $this->getDocumentPersister(), $path, ...$query));
Copy link
Member

Choose a reason for hiding this comment

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

Noted that this class extends Autocomplete, which had its constructor modified to accept a DocumentPersister. I assume the same is true for other classes in this file, which are themselves absent from this PR.

* }
* }
*/
class Search extends Stage implements SupportsAllSearchOperators
Copy link
Member

Choose a reason for hiding this comment

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

I noted that this doesn't extended the abstract class earlier in the PR, which means you had to modify the constructor and introduce a getDocumentPersister() method.

Out of curiosity, why can't it inherit the base class like other stages?

Copy link
Member

Choose a reason for hiding this comment

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

cc: @GromNaN

Copy link
Member Author

@GromNaN GromNaN Sep 29, 2025

Choose a reason for hiding this comment

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

I think because we don't want that the Search class implement SearchOperator, and the methods implemented by AbstractSearchOperator delegate to the Search class, while the Search class modifies its own state.

])
->willReturn(['search_articles']);
->with($this->anything())
->willReturnCallback(function (array $indexes) {
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm: you're mocking the response here to avoid requiring an Atlas cluster, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's a unit test that doesn't depend on a MongoDB server.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Outstanding question in Compound.php, which may apply to any other classes that had a similar behavior of assigning their own private DocumentPersister instance.

Also, a question in Search.php wasn't addressed. No changes required there but an answer would help my understanding.

I'll LGTM as the "private DocumentPersister" cleanup is straightforward.

* }
* }
*/
class Search extends Stage implements SupportsAllSearchOperators
Copy link
Member

Choose a reason for hiding this comment

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

cc: @GromNaN

@GromNaN GromNaN merged commit 07a30c5 into doctrine:2.13.x Sep 29, 2025
23 checks passed
@GromNaN GromNaN deleted the PHPORM-391 branch September 29, 2025 15:57
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.

2 participants