示例#1
0
 /**
  * Add a document to the index
  * @param DocumentInterface $document the document to index
  * @param bool $async whether or not to perform an async request.
  *
  * @return \Guzzle\Http\Message\Response|mixed the response from elastic search
  */
 public function index(DocumentInterface $document, $async = false)
 {
     $client = $async ? $this->getAsyncClient() : $this->getClient();
     $request = $client->put($document->getUrl())->setBody(json_encode($document->getSource()));
     return $this->perform($request, $async);
 }
 /**
  * @param DocumentInterface $document the document that is providing the data for this record.
  * Override this method to apply custom data from a search result to a new record.
  */
 public function parseElasticDocument(DocumentInterface $document)
 {
     $this->owner->setPrimaryKey($document->getId());
     if ($document instanceof SearchResult) {
         $this->owner->setElasticScore($document->getScore());
     }
     foreach ($document->getSource() as $attribute => $value) {
         $this->owner->{$attribute} = $value;
     }
 }