logo

English

Autocomplete

Notice !

Results are cached for 5 minutes approximately and changes (like updating a document) will not be applied for the same query until 5 minutes pass.
$lableb->autocomplete( $collection, $queryOptions, [$handler] )
  1. $collection: collection name you want to search for suggestions in.
  2. $queryOptions: an associatve array with search parameters.
  3. $handler: an optional parameter that has the value of suggest by default, specify it if you want to use a custom autocomplete handler.
Autocomplete Options (\$queryOptions):
OptionDescriptionRequiredExample
qsearch termyes'how to ma'
limithow many documents to fetchno10
user_ida unique user idno1254
user_ipuser IP addressno'55.22.11.6'
user_countryuser country codeno'CA'
You can specify any additional query string parameters if you need to.
Example:
try
{
  $response = $lableb->autocomplete( 'posts', [
    'q' => 'how to ma'
  ] );
}
catch( \Lableb\Exceptions\LablebException $e )
{
  echo $e->getMessage();
}

Example response:
There are two types of suggestions:
  1. Navigational suggestion which refers to an article
  2. Filter suggestion which has search filters that can be used with search
[
  'totalSuggestions' => 33,
  'suggestions' => [
    [
      'suggestion_type' => 'navigational',
      'id' => 1,
      'phrase' => 'How to make italian pizza',
      'date' => '2018-12-06T12:16:00.000+0000',
      'url' => 'https://funfunfood.com/2018/12/06/pizza',
      'feedbackUrl' => 'https://api-bahuth.lableb.com/api/v2/....'
    ],
    [
      'suggestion_type' => 'filter',
      'phrase' => 'Posts about pizza',
      'filters' => [
        'meta' => ['Pizza', 'Food']
      ]
    ]
  ]
  'totalFacets' => 0
  'facets' => Array
        (
        )
]

Notice !

Each result will have an additional field called feedbackUrl which you can perform a GET request on to submit autocomplete feedback