Example #1
0
 protected function saveNode($title, $content, $url, $date)
 {
     $content = $this->cleanContent($content);
     if (is_null($content)) {
         $this->counter['empty_url']++;
         return false;
     }
     $hashId = md5($url);
     $params = ['index' => 'sites', 'type' => 'default', 'id' => $hashId, 'body' => ['title' => $title, 'content' => $content, 'hash_id' => $hashId, 'date' => $date ? Carbon::createFromTimestamp($date)->toW3cString() : null, 'url' => $url]];
     try {
         $response = $this->client->index($params);
         if (!$response['created']) {
             $this->counter['updated']++;
         } else {
             $this->counter['indexed']++;
         }
     } catch (ElasticsearchException $e) {
         $this->error("# Cannot Index content of {$url}. Check \"failed:{$url}\" key in redis for more information");
         $this->redis->hMSet("failed:{$url}", ['error' => $e->getMessage(), 'params' => $url]);
         $this->counter['failed_index']++;
     }
     return true;
 }