Skip to content

Commit

Permalink
Fix having to reindex if a bundle label has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
almasaeed2010 committed Jan 26, 2018
1 parent 63891a2 commit 3cb580e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
19 changes: 9 additions & 10 deletions includes/Elasticsearch/ESInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,26 +558,25 @@ public function getIndices() {
* @return array
*/
public function getAllCategories($version = NULL) {
$node_types = [];
$entity_types = [];
$index_name = [];
$types = [];
$indices = $this->getIndices();

if (in_array('website', $indices) && ($version === NULL || $version === 2)) {
// Get all node types from the node table.
$node_types = db_query("SELECT DISTINCT(type) FROM {node}")->fetchCol('type');
$index_name[] = 'website';
$node_types = db_query("SELECT DISTINCT(type) FROM {node}")->fetchAll();
foreach ($node_types as $type) {
$types[$type->type] = $type->type;
}
}

if (in_array('entities', $indices) && ($version === NULL || $version === 3)) {
// Get all tripal entity types from the tripal_bundle table.
$entity_types = db_query("SELECT DISTINCT(label) FROM {tripal_bundle}")->fetchCol('label');
$index_name[] = 'entities';
$entity_types = db_query("SELECT name, label FROM {tripal_bundle}")->fetchAll();
foreach ($entity_types as $type) {
$types[$type->name] = $type->label;
}
}

$types = array_merge($node_types, $entity_types);
sort($types);

return $types;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/Jobs/EntitiesIndexJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected function get() {
* @return array
*/
protected function getMultipleEntities() {
$query = 'SELECT tripal_entity.id AS entity_id, title, label AS bundle_label
$query = 'SELECT tripal_entity.id AS entity_id, title, tripal_bundle.name AS bundle_label
FROM tripal_entity
JOIN tripal_bundle ON tripal_entity.term_id = tripal_bundle.term_id
WHERE status=1 AND bundle=:bundle
Expand Down
9 changes: 5 additions & 4 deletions tripal_elasticsearch.api.inc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function build_search_query_from_field_content_pairs(array $field_content_pairs,
* Function to theme search results count by node type.
* This function returns an html list.
*
* @throws \Exception
* @return string
*/
function get_website_search_results_category_list($keyword) {
Expand All @@ -179,12 +180,12 @@ function get_website_search_results_category_list($keyword) {

// Save search results count to an associative array with node types as keys.
$search_website_count_by_category = [];
foreach ($types as $node_type) {
foreach ($types as $type => $label) {
try {
$count = $es->setWebsiteSearchParams($keyword, $node_type, implode(',', $index_name))
$count = $es->setWebsiteSearchParams($keyword, $type, implode(',', $index_name))
->count();
if ($count > 0) {
$search_website_count_by_category[$node_type] = $count;
$search_website_count_by_category[$type] = $count;
}
} catch (Exception $exception) {
drupal_set_message('The search service is currently unavailable. Please try again later.', 'error');
Expand Down Expand Up @@ -216,7 +217,7 @@ function get_website_search_results_category_list($keyword) {

$items = [];
foreach ($website_search_by_node_type['count'] as $category => $count) {
$text = $category . ' (' . $count . ')';
$text = $types[$category] . ' (' . $count . ')';
$url = 'tripal_elasticsearch/search_website/' . $category;
$items[] = l($text, $url, [
'query' => [
Expand Down

0 comments on commit 3cb580e

Please sign in to comment.