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

Add an “autocomplete” helper to Laravel Builder

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • laravel-5.2.0
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • PHP Drivers
    • Completed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Autocompletion is a common use-case for the search engine. The following method will be added to MongoDB\Laravel\Query\Builder:

       

      class Builder {
          /**
           * @param bool|array{maxEdits?:int, prefixLength?:int, maxExpansions?:int} $fuzzy
           * @return string[]
           */
          function autocomplete(string $fieldPath, string $query, int $limit = 20, bool|array $fuzzy = false, bool $sequential = false, string $index = 'default'): array;
      }
      

       

      This method uses the autocomplete operator and returns a list of suggested strings.

      $sequential is a boolean that translates tokenOrder = any|sequential.

       

      This method can be used on any DocumentModel class

       

      Movie::autocomplete('title', 'fam')
      // return ['The Family That Preys', 'My Family and Other Animals', ...]
      

       

      Runs the following aggregation:

       

      [
        {
          $search: {
            autocomplete: {
              query:'fam',
              path:'title',
            }
          }
        },
        {
          $project: {
            title: 1
          }
        }
      ]
      

       

      color: Color value is invalid

      If there is no search index on the given collection, no results are returned.

      We will not add a helper to create an “autocompletion” index. Relying on the documentation to create indexes with more use-cases.

       

      {
        "mappings": {
          "dynamic": false,
          "fields": {
            "title": {
              "foldDiacritics": true,
              "maxGrams": 15,
              "minGrams": 2,
              "tokenization": "edgeGram",
              "type": "autocomplete"
            }
          }
        }
      }
      

       

       

            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