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;
}

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