From b02f17540195e1c9f933b40b0176a6f01bf1be6d Mon Sep 17 00:00:00 2001 From: brettp Date: Sun, 8 Nov 2009 00:09:09 +0000 Subject: Added super-basic support for searching comments. git-svn-id: http://code.elgg.org/elgg/trunk@3636 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/search/search_hooks.php | 78 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'mod/search/search_hooks.php') diff --git a/mod/search/search_hooks.php b/mod/search/search_hooks.php index abe85d962..89e7ecce0 100644 --- a/mod/search/search_hooks.php +++ b/mod/search/search_hooks.php @@ -30,7 +30,7 @@ function search_objects_hook($hook, $type, $value, $params) { //@todo allow sorting by recent time $params['order_by'] = NULL; - +var_dump($params); $entities = elgg_get_entities($params); $params['count'] = TRUE; $count = elgg_get_entities($params); @@ -203,3 +203,79 @@ function search_custom_types_tags_hook($hook, $type, $value, $params) { return $value; } + +/** + * Return default results for searches on comments. + * + * @param unknown_type $hook + * @param unknown_type $type + * @param unknown_type $value + * @param unknown_type $params + * @return unknown_type + */ +function search_comments_hook($hook, $type, $value, $params) { + global $CONFIG; + + $query = $params['query']; + $params['annotation_names'] = array('generic_comment', 'group_topic_post'); + + $params['joins'] = array( + "JOIN {$CONFIG->dbprefix}annotations a on e.guid = a.entity_guid", + "JOIN {$CONFIG->dbprefix}metastrings msn on a.name_id = msn.id", + "JOIN {$CONFIG->dbprefix}metastrings msv on a.value_id = msv.id" + ); + + $fields = array('string'); + $search_where = search_get_where_sql('msv', $fields, $params); + + $e_access = get_access_sql_suffix('e'); + $a_access = get_access_sql_suffix('a'); + // @todo this can probably be done through the api.. + $q = "SELECT DISTINCT a.*, msv.string as comment FROM {$CONFIG->dbprefix}annotations a + JOIN {$CONFIG->dbprefix}metastrings msn ON a.name_id = msn.id + JOIN {$CONFIG->dbprefix}metastrings msv ON a.value_id = msv.id + JOIN {$CONFIG->dbprefix}entities e ON a.entity_guid = e.guid + WHERE msn.string IN ('generic_comment', 'group_topic_post') + AND ($search_where) + AND $e_access + AND $a_access + + LIMIT {$params['offset']}, {$params['limit']} + "; + $comments = get_data($q); + + // need to return actual entities + // add the volatile data for why these entities have been returned. + $entities = array(); + foreach ($comments as $comment) { + $tags = implode(',', $entity->tags); + if (!$entity = get_entity($comment->entity_guid)) { + continue; + } + $comment_str = search_get_relevant_substring($comment->comment, $query, '', ''); + $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); + $entities[] = $entity; + } + + return array( + 'entities' => $entities, + 'count' => count($entities), + ); +} + +/** + * Register comments as a custom search type. + * + * @param unknown_type $hook + * @param unknown_type $type + * @param unknown_type $value + * @param unknown_type $params + * @return unknown_type + */ +function search_custom_types_comments_hook($hook, $type, $value, $params) { + $value[] = 'comments'; + return $value; +} + -- cgit v1.2.3