Skip to content

Can't add a filter on a text search #2733

Open
@fullbl

Description

@fullbl

Bug Report

Q A
BC Break yes
Version 5.0.1

Summary

When adding a filter, it goes always in first stage. If the query already have a match two stages will be created, making mongodb throw an exception.
Documentation states that $match stage that includes a $text must be the first stage in the pipeline.

Current behavior

The stage that comes from filters will always be the first in pipeline.

How to reproduce

  1. create a filter
final class ExcludeSoftDeletedFilter extends BsonFilter
{
    public function addFilterCriteria(ClassMetadata $targetDocument): array
    {
        return [
            'deletedAt' => null,
        ];
    }
}
  1. run a query with texts:
$this->createAggregationBuilder()
            ->match()
            ->field('field')
            ->text('value')
An exception occured, transforming to an Error resource. {"exception":"[object] (MongoDB\\Driver\\Exception\\CommandException(code: 17313): $match with $text is only allowed as the first pipeline stage at /var/www/html/vendor/mongodb/mongodb/src/Operation/Aggregate.php:383

Expected behavior

In my opinion, the CriteriaMerger should be used when merging the attributes, or there should be a "reorder" before submitting the query, so the text stage should go first

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions