Skip to content

Conversation

@GromNaN
Copy link
Contributor

@GromNaN GromNaN commented Sep 15, 2025

Q A
Branch? main
Tickets -
License MIT
Doc PR TODO

This is a work in progress

The MongoDB $search aggregation uses a Lucene-based index for full-text search. This stage must be the first of the aggregation pipeline.

This is different form the existing ODM SearchFilter which uses the standard query operators.

Todo:

  • Move sort in the $search stage
  • Move limit in the $search stage
  • Add tests
  • Add doc

Usage

#[ApiResource(
    shortName: 'products',
    operations: [
        new GetCollection(
            parameters: [
                'name' => new QueryParameter(
                    schema: ['type' => 'string', 'default' => null],
                    filter: new AtlasSearchFilter(
                        index: 'search_index',
                        operator: 'text',
                        term: 'must'
                    ),
                ),
                'description' => new QueryParameter(
                    schema: ['type' => 'string', 'default' => null],
                    filter: new AtlasSearchFilter(
                        index: 'search_index',
                        operator: 'text',
                        term: 'should',
                    ),
                ),
                'search' => new QueryParameter(
                    schema: ['type' => 'string', 'default' => null],
                    filter: new AtlasSearchFilter(
                        index: 'search_index',
                        operator: 'queryString',
                        term: 'must',
                    ),
                    property: 'name',
                ),
            ]
        ),
    ]
)]
#[MongoDB\Document(collection: 'products')]
#[MongoDB\SearchIndex(name: 'search_index', dynamic: true)]
class Product
{
    #[MongoDB\Id] public string $id;
    #[MongoDB\Field] public ?string $name;
    #[MongoDB\Field] public ?string $description;
    #[MongoDB\Field] public ?string $brand;
}

@GromNaN GromNaN changed the title feat(doctrine): Add MongoDB Atlas Search filter feat(mongodb): Add MongoDB Atlas Search filter Oct 20, 2025
@stale
Copy link

stale bot commented Dec 19, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 19, 2025
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.

1 participant