diff --git a/includes/Elasticsearch/ESInstance.php b/includes/Elasticsearch/ESInstance.php index cf22df11..339db16c 100644 --- a/includes/Elasticsearch/ESInstance.php +++ b/includes/Elasticsearch/ESInstance.php @@ -37,7 +37,7 @@ class ESInstance { * Establishes a connection to a host. * * @param null $host - * + * @throws \Exception * @return void */ public function __construct($host = NULL) { @@ -244,14 +244,9 @@ public function setTableSearchParams( * * @return $this */ - public function setIndexParams( - $index_name, - $shards = 5, - $replicas = 0, - $tokenizer = 'standard', - $token_filters = [], - $field_mapping_types = [] - ) { + public function setIndexParams($index_name, $shards = 5, $replicas = 0, + $tokenizer = 'standard', $token_filters = [], + $field_mapping_types = []) { $analysis = [ 'analyzer' => [ $index_name => [ @@ -472,13 +467,7 @@ public function bulkUpdate($index, $entries, $type = NULL, $id_key = NULL) { * * @return array */ - public function bulk( - $operation, - $index, - $entries, - $type = NULL, - $id_key = NULL - ) { + public function bulk($operation, $index, $entries, $type = NULL, $id_key = NULL) { if (count($entries) === 0) { return []; } @@ -520,7 +509,7 @@ public function bulk( * Paginate search results. * * @param $per_page - * + * @throws \Exception * @return array */ public function paginate($per_page) { @@ -555,6 +544,7 @@ public function getIndices() { /** * Get all available categories. * + * @throws \Exception * @return array */ public function getAllCategories($version = NULL) { @@ -609,9 +599,10 @@ public function getIndexMappings($index) { /** * Returns results from all indices. * - * @param $terms - * @param $size - * + * @param string $terms + * @param int $size + * @param string|null $category + * @throws \Exception * @return array */ public function searchWebIndices($terms, $size, $category = NULL) { @@ -684,8 +675,9 @@ public function deleteAllRecords($index_name, $type = NULL) { /** * Get a single record. * - * @param $index - * @param $id + * @param string $index + * @param string $type + * @param int $id * * @return array */ diff --git a/includes/Elasticsearch/ESQueue.php b/includes/Elasticsearch/ESQueue.php index 9cd01206..271c1871 100644 --- a/includes/Elasticsearch/ESQueue.php +++ b/includes/Elasticsearch/ESQueue.php @@ -152,7 +152,7 @@ public static function run($job) { $job->handle(); $total = $job->total(); } catch (Exception $exception) { - watchdog('tripal_elasticsearch', $exception->getMessage(), [], WATCHDOG_ERROR); + tripal_report_error('tripal_elasticsearch', TRIPAL_ERROR, $exception->getMessage()); $total = $job->chunk ?: 1; } diff --git a/includes/Jobs/EntitiesIndexJob.php b/includes/Jobs/EntitiesIndexJob.php index ce954292..bdb52111 100644 --- a/includes/Jobs/EntitiesIndexJob.php +++ b/includes/Jobs/EntitiesIndexJob.php @@ -86,20 +86,24 @@ public function __construct($bundle, $entity_id = NULL, $round = 1) { * Bulk index all entries if there are more than one. */ public function handle() { - $this->es = new ESInstance(); - $records = $this->get(); - $records = $this->loadContent($records); - - if ($this->total > 1) { - if (!$this->shouldUpdate) { - $this->es->bulkIndex($this->index, $records, $this->index, 'entity_id'); + try { + $this->es = new ESInstance(); + $records = $this->get(); + $records = $this->loadContent($records); + + if ($this->total > 1) { + if (!$this->shouldUpdate) { + $this->es->bulkIndex($this->index, $records, $this->index, 'entity_id'); + } + else { + $this->es->bulkUpdate($this->index, $records, $this->index, 'entity_id'); + } } - else { - $this->es->bulkUpdate($this->index, $records, $this->index, 'entity_id'); + elseif (count($records) > 0) { + $this->es->createEntry($this->index, $this->index, $records[0]->entity_id, $records[0]); } - } - elseif (count($records) > 0) { - $this->es->createEntry($this->index, $this->index, $records[0]->entity_id, $records[0]); + } catch (Exception $exception) { + tripal_report_error('tripal_elasticsearch', TRIPAL_ERROR, $exception->getMessage()); } } @@ -180,9 +184,9 @@ protected function loadContent($records) { * @return array */ protected function getPriorityList($fields) { -// if ($this->id !== NULL) { -// return $this->getAllFields($fields); -// } + // if ($this->id !== NULL) { + // return $this->getAllFields($fields); + // } return $this->prioritizeFields($fields); } @@ -241,7 +245,7 @@ protected function prioritizeFields($fields) { // If we find a match for the priority round add to the should-be-indexed fields list // Or if this is a single entity add all the fields to the list if (isset($indexed[$id]) && ($indexed[$id] == $this->priority_round || $this->id !== NULL)) { - if($this->id !== null && $indexed[$id] == 0) { + if ($this->id !== NULL && $indexed[$id] == 0) { // This field is not supposed to be indexed continue; }