logo

English

Index Documents

$lableb->index( $collection, $documents )
  1. $collection: what collection you want to index documents on, e.x posts.
  2. $documents: a document or an array of documents to be indexed.
Example:
$collection = 'posts';
$documents = [[
  "id" => 1,
  "title" => "this is a title 1",
  "content" => "this is article content",
  "category" => ["cat1", "cat2"],
  "tags" => ["tag1", "tag2"],
  "url" => "https://solutions.lableb.com/en/doc/php-sdk/index-documents",
  "authors" => ["Lableb Team"],
  "date" => new \DateTime()
]];

try
{
  $response = $lableb->index( $collection, $documents );
}
catch ( \Lableb\Exceptions\LablebException $e )
{
  echo $e->getStatus()." - ".$e->getMessage();
}


Example response:
[
  "indexed" => true,
  "message" => "1 documents has been indexed"
]

Update Indexed Documents

To update an indexed document, just re-index the document with the same ID.