aboutsummaryrefslogtreecommitdiff
path: root/mod/search/search_hooks.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-15 04:27:19 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-15 04:27:19 +0000
commita4df77a015527dea272d8b643e89a33f8929361b (patch)
tree903896a5c55e3337d02efea214c16ab2f7ce4b64 /mod/search/search_hooks.php
parent9fb9b8565d6a95df0264ef0054106df6b2d3943e (diff)
downloadelgg-a4df77a015527dea272d8b643e89a33f8929361b.tar.gz
elgg-a4df77a015527dea272d8b643e89a33f8929361b.tar.bz2
Search changes.
Fixes #1376: Only fetching ft_min_word_length if the query != false. Using IN BOOLEAN MODE for metadata search (comments, tags) to avoid a fulltext index on the metastrings table. Slower for search, faster for site. Simplified and modularized logic for pulling out relevant substrings and highlighting. Corrected the elipse oddities in relevancy substring concatenation. Added pagination on non-homepages. Added missing language strings. Updated and standardized comment results listings. Repeat query in searchbar. Dealing with comments on unavailable entities better (though not well). Increased default word context to 30 characters. Decreased default context max length to 300 characters. Promise to start making atomic commits real soon now. git-svn-id: http://code.elgg.org/elgg/trunk@3684 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/search/search_hooks.php')
-rw-r--r--mod/search/search_hooks.php40
1 files changed, 35 insertions, 5 deletions
diff --git a/mod/search/search_hooks.php b/mod/search/search_hooks.php
index f7a49400f..8f0a62703 100644
--- a/mod/search/search_hooks.php
+++ b/mod/search/search_hooks.php
@@ -229,7 +229,10 @@ function search_comments_hook($hook, $type, $value, $params) {
);
$fields = array('string');
- $search_where = search_get_where_sql('msv', $fields, $params);
+
+ // force IN BOOLEAN MODE since fulltext isn't
+ // available on metastrings (and boolean mode doesn't need it)
+ $search_where = search_get_where_sql('msv', $fields, $params, FALSE);
$e_access = get_access_sql_suffix('e');
$a_access = get_access_sql_suffix('a');
@@ -245,17 +248,44 @@ function search_comments_hook($hook, $type, $value, $params) {
LIMIT {$params['offset']}, {$params['limit']}
";
+
$comments = get_data($q);
+//elgg_get_entities()
+ $q = "SELECT count(DISTINCT a.id) as total 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
+ ";
+
+ $result = get_data($q);
+ $count = $result[0]->total;
+ // @todo if plugins are disabled causing subtypes
+ // to be invalid and there are comments on entities of those subtypes,
+ // the counts will be wrong here and results might not show up correctly,
+ // especially on the search landing page, which only pulls out two results.
+
+ // probably better to check against valid subtypes than to do what I'm doing.
+
// 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;
+ $entity = get_entity($comment->entity_guid);
+
+ // hic sunt dracones
+ if (!$entity) {
+ //continue;
+ $entity = new ElggObject();
+ $entity->setVolatileData('search_unavailable_entity', TRUE);
}
+
$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);
@@ -264,7 +294,7 @@ function search_comments_hook($hook, $type, $value, $params) {
return array(
'entities' => $entities,
- 'count' => count($entities),
+ 'count' => $count,
);
}