aboutsummaryrefslogtreecommitdiff
path: root/mod/search/search_hooks.php
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2013-07-05 20:44:02 -0400
committercash <cash.costello@gmail.com>2013-07-05 20:44:02 -0400
commit597323ce5dece2597accbf98d55c2d2fa6891f4f (patch)
treea2c83c233c14633e194d8981323530d3691dcf6b /mod/search/search_hooks.php
parenta873fa6429460ccebbfdb5b7d17f124c80a6ee5c (diff)
downloadelgg-597323ce5dece2597accbf98d55c2d2fa6891f4f.tar.gz
elgg-597323ce5dece2597accbf98d55c2d2fa6891f4f.tar.bz2
Fixes #5708 search supports multiple comments on the same entity
Diffstat (limited to 'mod/search/search_hooks.php')
-rw-r--r--mod/search/search_hooks.php28
1 files changed, 20 insertions, 8 deletions
diff --git a/mod/search/search_hooks.php b/mod/search/search_hooks.php
index c92003c7e..923cf0aa8 100644
--- a/mod/search/search_hooks.php
+++ b/mod/search/search_hooks.php
@@ -405,14 +405,19 @@ function search_comments_hook($hook, $type, $value, $params) {
// don't continue if nothing there...
if (!$count) {
- return array ('entities' => array(), 'count' => 0);
+ return array('entities' => array(), 'count' => 0);
}
-
- $order_by = search_get_order_by_sql('e', null, $params['sort'], $params['order']);
+
+ // no full text index on metastrings table
+ if ($params['sort'] == 'relevance') {
+ $params['sort'] = 'created';
+ }
+
+ $order_by = search_get_order_by_sql('a', null, $params['sort'], $params['order']);
if ($order_by) {
$order_by = "ORDER BY $order_by";
}
-
+
$q = "SELECT DISTINCT a.*, msv.string as comment FROM {$db_prefix}annotations a
JOIN {$db_prefix}metastrings msn ON a.name_id = msn.id
JOIN {$db_prefix}metastrings msv ON a.value_id = msv.id
@@ -450,10 +455,17 @@ function search_comments_hook($hook, $type, $value, $params) {
}
$comment_str = search_get_highlighted_relevant_substrings($comment->comment, $query);
- $entity->setVolatileData('search_match_annotation_id', $comment->id);
- $entity->setVolatileData('search_matched_comment', $comment_str);
- $entity->setVolatileData('search_matched_comment_owner_guid', $comment->owner_guid);
- $entity->setVolatileData('search_matched_comment_time_created', $comment->time_created);
+ $comments_data = $entity->getVolatileData('search_comments_data');
+ if (!$comments_data) {
+ $comments_data = array();
+ }
+ $comments_data[] = array(
+ 'annotation_id' => $comment->id,
+ 'text' => $comment_str,
+ 'owner_guid' => $comment->owner_guid,
+ 'time_created' => $comment->time_created,
+ );
+ $entity->setVolatileData('search_comments_data', $comments_data);
$entities[] = $entity;
}