core
core copied to clipboard
feat(mongodb): Add MongoDB Atlas Search filter
| 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
sortin the$searchstage - [ ] Move
limitin the$searchstage - [ ] 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;
}