-
Type:
New Feature
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Laravel
-
None
Writing a search pipeline requires reading the documentation: https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/
Current code:
$articles = Article::aggregate() ->search([ 'index' => 'default', 'text' => ['query' => 'John Doe', 'path' => 'title'], 'sort' => ['published_at' => -1], ]) ->get()
New syntax:
use MongoDB\Builder\Search; $articles = Article::search( index: 'default', text: Search::text(query: 'John Doe', path: 'title'], sort: ['published_at' => -1] ]);
Signature of the new method for the $search stage.
namespace MongoDB\Laravel\Query; class Builder extends \Illuminate\Database\Query\Builder { // Other existing methods public function search( SearchOperator|array|stdClass $operator, ?string $index = null, ?array $highlight = null, ?bool $concurrent = null, ?string $searchAfter = null, ?string $searchBefore = null, ?bool $scoreDetails = null, // @param array<string, int> ?array $sort = null, ?bool $returnStoredSource = null, ?array $tracking = null, ): AggregationBuilder { // implementation will call $this->aggregate() } }
An advanced PHPStan array-shape type will be defined for all other operators.