logo

English

Search Documents

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->search( $collection, $queryOptions, $handler )
  1. $collection: collection name you want to search in.
  2. $queryOptions: an associative array of search parameters.
  3. $handler: an optional parameter that has the value of default by default, specify it if you want to use a custom search handler.
Search Parameters ($queryOptions):
OptionDescriptionRequiredExample
qsearch termyes'how to make pizza'
filtersearch filtersno[ 'tags' => 'delicious' ]
limithow many documents to fetchno10
skiphow many documents to skip (offset)no50
sortorder of documentsno'date asc' or 'date desc', in general it's field_name + order
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, for example 'lang' => 'ar' or 'tag' => ['tag1', 'tag2'].
Example:
try
{
  $response = $lableb->search( 'posts', [
    'q' => 'how to make pizza',
    'filter' => [
      'category' => 'Food',
      'tags' => [ 'delicious', 'pizza' ]
    ],
    'author' => 'Lableb Team',
    'skip' =>0,
    'limit'=>1,
    'sort' =>'date asc'
  ] );
}
catch( \Lableb\Exceptions\LablebException $e )
{
  echo $e->getStatus()." - ".$e->getMessage();
}

Example Response:
[
  'totalDocuments' => 50,
  'results' => [
    [
      'id' => 1,
      'title' => 'How to make italian pizza',
      'content' => 'The italian pizza, margherita ...',
      'date' => '2018-12-06T12:16:00.000+0000',
      'url' => 'https://funfunfood.com/2018/12/06/pizza',
      'image' => 'https://funfunfood.com/static/pizza.png',
      'feedbackUrl' => 'https://api-bahuth.lableb.com/api/v2/....'
    ],
  ],
  'totalFacets' => 50,
  'facets' => [
    'categories' => [
      [
        'value' => 'Food',
        'count' => 8
      ]
    ],
    'tags' => [],
    'authors' => [
      [
        'value' => 'Lableb Team',
        'count' => 2
      ]
    ],
    'year' => []
  ]
]

Notice

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