Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-275

Add search helpers in Laravel Builder

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • laravel-5.2.0
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • PHP Drivers
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?

      Add the methods Model::search and Model::autocomplete to the API documentation.

      Create a page dedicated to Atlas Search (create index, perform search).

      2. Would you like the user to see examples of the syntax and/or executable code and its output?

      Example in the ticket.
      3. Which versions of the driver/connector does this apply to?

      mongodb/laravel-mongodb 5.2+ and mongodb/mongodb 1.21+

      Show
      1. What would you like to communicate to the user about this feature? Add the methods Model::search and Model::autocomplete to the API documentation. Create a page dedicated to Atlas Search (create index, perform search). 2. Would you like the user to see examples of the syntax and/or executable code and its output? Example in the ticket. 3. Which versions of the driver/connector does this apply to? mongodb/laravel-mongodb 5.2+ and mongodb/mongodb 1.21+
    • None
    • None
    • None
    • None
    • None
    • 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.

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None