]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #5708 search supports multiple comments on the same entity
authorcash <cash.costello@gmail.com>
Sat, 6 Jul 2013 00:44:02 +0000 (20:44 -0400)
committercash <cash.costello@gmail.com>
Sat, 6 Jul 2013 00:44:02 +0000 (20:44 -0400)
mod/search/search_hooks.php
mod/search/views/default/search/comments/entity.php
mod/search/views/rss/search/comments/entity.php

index c92003c7e551093728d880e0508cff86fdeb7285..923cf0aa8b62bdd3cfe672a0c8c21522326c08c9 100644 (file)
@@ -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;
        }
 
index 005bb270c4b5a4f2ecded81673de692660e13249..77e95084326ec6d7898626562896dc2b6b0ad7fd 100644 (file)
@@ -6,8 +6,11 @@
  */
 
 $entity = $vars['entity'];
+$comments_data = $entity->getVolatileData('search_comments_data');
+$comment_data = array_shift($comments_data);
+$entity->setVolatileData('search_comments_data', $comments_data);
 
-$owner = get_entity($entity->getVolatileData('search_matched_comment_owner_guid'));
+$owner = get_entity($comment_data['owner_guid']);
 
 if ($owner instanceof ElggUser) {
        $icon = elgg_view_entity_icon($owner, 'tiny');
@@ -38,12 +41,12 @@ if ($entity->getVolatileData('search_unavailable_entity')) {
        $title = elgg_echo('search:comment_on', array($title));
 
        // @todo this should use something like $comment->getURL()
-       $url = $entity->getURL() . '#comment_' . $entity->getVolatileData('search_match_annotation_id');
+       $url = $entity->getURL() . '#comment_' . $comment_data['annotation_id'];
        $title = "<a href=\"$url\">$title</a>";
 }
 
-$description = $entity->getVolatileData('search_matched_comment');
-$tc = $entity->getVolatileData('search_matched_comment_time_created');;
+$description = $comment_data['text'];
+$tc = $comment_data['time_created'];
 $time = elgg_view_friendly_time($tc);
 
 $body = "<p class=\"mbn\">$title</p>$description";
index 869779f35a1e39240aab13b5af6ea02ca3fba434..e47afec4a16295d34f9a2f0633324a67095a9e1c 100644 (file)
@@ -6,9 +6,12 @@
  */
 
 $entity = $vars['entity'];
+$comments_data = $entity->getVolatileData('search_comments_data');
+$comment_data = array_shift($comments_data);
+$entity->setVolatileData('search_comments_data', $comments_data);
 
 $author_name = '';
-$comment_author_guid = $entity->getVolatileData('search_matched_comment_owner_guid');
+$comment_author_guid = $comment_data['owner_guid'];
 $author = get_user($comment_author_guid);
 if ($author) {
        $author_name = $author->name;
@@ -34,11 +37,11 @@ if ($entity->getVolatileData('search_unavailable_entity')) {
 
        $title = elgg_echo('search:comment_on', array($title));
        $title .= ' ' . elgg_echo('search:comment_by') . ' ' . $author_name;
-       $url = $entity->getURL() . '#annotation-' . $entity->getVolatileData('search_match_annotation_id');
+       $url = $entity->getURL() . '#annotation-' . $comment_data['annotation_id'];
 }
 
-$description = $entity->getVolatileData('search_matched_comment');
-$tc = $entity->getVolatileData('search_matched_comment_time_created');;
+$description = $comment_data['text'];
+$tc = $comment_data['time_created'];
 
 ?>