diff --git a/theme/templates/elasticsearch_results.tpl.php b/theme/templates/elasticsearch_results.tpl.php new file mode 100644 index 00000000..4de732a3 --- /dev/null +++ b/theme/templates/elasticsearch_results.tpl.php @@ -0,0 +1,39 @@ + +

+ + + + title ?> + +
+ + title, $row->url) ?>
+ + + Content type: type ?>
+ + content)): ?> + content ?>
+ + + + + + url, 0, 40) . (strlen($row->url) > 40 ? '...' : '') ?> + + + + + url, '/')); + $url = substr($url, 0, 40) . (strlen($url) > 40 ? '...' : '') + ?> + url, [ + 'attributes' => [ + 'class' => ['text-muted'], + ], + ]) ?> + + +

+title = $item->title; if (isset($item->nid)) { - $row = '

' . l($item->title, 'node/' . $item->nid) . '

'; + // $row = '

' . l($item->title, 'node/' . $item->nid) . '

'; + // if ($base_url) { + // $row = '

' . $item->title . '

'; + // } + if ($base_url) { - $row = '

' . $item->title . '

'; + $row->url = "{$base_url}/node/{$item->nid}"; + } + else { + $row->url = "/node/{$item->nid}"; } } else { - $row = '

' . l($item->title, 'bio_data/' . $item->entity_id) . '

'; + // $row = '

' . l($item->title, 'bio_data/' . $item->entity_id) . '

'; + // if ($base_url) { + // $row = '

' . $item->title . '

'; + // } + if ($base_url) { - $row = '

' . $item->title . '

'; + $row->url = "{$base_url}/bio_data/{$item->entity_id}"; + } + else { + $row->url = "/bio_data/{$item->entity_id}"; } } + $row->type = ''; if (property_exists($item, 'bundle_label')) { $type = isset($types[$item->bundle_label]) ? $types[$item->bundle_label] : $item->bundle_label; - $row .= '
Type: ' . $type . '
'; + // $row .= '
Type: ' . $type . '
'; + $row->type = $type; } elseif (property_exists($item, 'type')) { $type = isset($types[$item->type]) ? $types[$item->type] : $item->type; - $row .= '
Type: ' . $type . '
'; + // $row .= '
Type: ' . $type . '
'; + $row->type = $type; } + $row->content = ''; if (property_exists($item, 'highlight')) { - $row .= '

' . $item->highlight . '

'; + // $row .= '

' . $item->highlight . '

'; + $row->content = $item->highlight; } - $rows[] = [$row]; + $rows[] = $row; } - $output = theme('table', [ - 'header' => [], + // $output = theme('table', [ + // 'header' => [], + // 'rows' => $rows, + // 'attributes' => [ + // 'id' => 'es-search-results-table', + // ], + // ]); + $output = theme('elasticsearch_results', [ 'rows' => $rows, - 'attributes' => [ - 'id' => 'es-search-results-table', - ], + 'base_url' => $base_url ]); if ($pager) { @@ -427,4 +453,4 @@ function get_table_search_result_table($search_results, $index_name, $total) { $output .= theme('pager', ['quantity', $total]); return $output; -} \ No newline at end of file +} diff --git a/tripal_elasticsearch.module b/tripal_elasticsearch.module index 9deaf620..8f07bf8a 100644 --- a/tripal_elasticsearch.module +++ b/tripal_elasticsearch.module @@ -337,6 +337,17 @@ function tripal_elasticsearch_theme($existing, $type, $theme, $path) { 'render element' => 'content', 'path' => "$path/theme/templates", ], + 'elasticsearch_results' => [ + 'template' => 'elasticsearch_results', + // 'render element' => 'elements', + 'path' => "$path/theme/templates", + 'variables' => [ + // The results array + 'rows' => [], + // The base url of the site + 'base_url' => null + ] + ], ]; return $themes; @@ -575,6 +586,7 @@ function tripal_elasticsearch_block_view($delta = '') { * tripal_elasticsearch_search_results_category_page_callback * * @param string $node_type Category name + * @throws Exception */ function tripal_elasticsearch_web_search_results_page_callback($node_type = '') { $keyword = isset($_GET['search_box']) ? $_GET['search_box'] : '';