aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-06 01:48:35 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-06 01:48:35 +0000
commita36e8f2cf884527f7a365158f21a44f4a12a6151 (patch)
treec16537551fe2afc57bce15bc0e391d9529a74fcb
parent70c5da31e5d4ab5393d7fb14eff33a1db36c3a02 (diff)
downloadelgg-a36e8f2cf884527f7a365158f21a44f4a12a6151.tar.gz
elgg-a36e8f2cf884527f7a365158f21a44f4a12a6151.tar.bz2
Added default object search.
git-svn-id: http://code.elgg.org/elgg/trunk@3622 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/objects.php82
1 files changed, 79 insertions, 3 deletions
diff --git a/engine/lib/objects.php b/engine/lib/objects.php
index 7e21550aa..b928af2fe 100644
--- a/engine/lib/objects.php
+++ b/engine/lib/objects.php
@@ -344,10 +344,86 @@ function get_object_sites($object_guid, $limit = 10, $offset = 0) {
/**
* Runs unit tests for ElggObject
*/
-register_plugin_hook('unit_test', 'system', 'objects_test');
-
function objects_test($hook, $type, $value, $params) {
global $CONFIG;
$value[] = "{$CONFIG->path}engine/tests/objects/objects.php";
return $value;
-} \ No newline at end of file
+}
+
+
+/**
+ * Returns a formatted list of objects suitable for injecting into search.
+ *
+ */
+function search_list_objects_by_name($hook, $user, $returnvalue, $tag) {
+ // Change this to set the number of users that display on the search page
+ $threshold = 4;
+
+ $object = get_input('object');
+
+ if (!get_input('offset') && (empty($object) || $object == 'user')) {
+ if ($users = search_for_user($tag,$threshold)) {
+ $countusers = search_for_user($tag,0,0,"",true);
+
+ $return = elgg_view('user/search/startblurb',array('count' => $countusers, 'tag' => $tag));
+ foreach($users as $user) {
+ $return .= elgg_view_entity($user);
+ }
+ $return .= elgg_view('user/search/finishblurb',array('count' => $countusers, 'threshold' => $threshold, 'tag' => $tag));
+ return $return;
+
+ }
+ }
+}
+
+/**
+ * Return default results for searches on objects.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ * @return unknown_type
+ */
+function objects_search_hook($hook, $type, $value, $params) {
+ global $CONFIG;
+
+ $query = $params['query'];
+
+ $join = "JOIN {$CONFIG->dbprefix}objects_entity oe ON e.guid = oe.guid";
+ $params['joins'] = array($join);
+
+ $where = "(oe.guid = e.guid
+ AND (oe.title LIKE '%$query%'
+ OR oe.description LIKE '%$query%'
+ )
+ )";
+ $params['wheres'] = array($where);
+
+ $entities = elgg_get_entities($params);
+ $params['count'] = TRUE;
+ $count = elgg_get_entities($params);
+
+ // no need to continue if nothing here.
+ if (!$count) {
+ return array('entities' => array(), 'count' => $count);
+ }
+
+ // add the volatile data for why these entities have been returned.
+ foreach ($entities as $entity) {
+ $title = search_get_relevant_substring($entity->title, $query, '<strong class="searchMatch">', '</strong>');
+ $entity->setVolatileData('search_matched_title', $title);
+
+ $desc = search_get_relevant_substring($entity->description, $query, '<strong class="searchMatch">', '</strong>');
+ $entity->setVolatileData('search_matched_description', $desc);
+ }
+
+ return array(
+ 'entities' => $entities,
+ 'count' => $count,
+ );
+}
+
+register_elgg_event_handler('init', 'system', 'objects_init', 0);
+register_plugin_hook('search', 'object', 'objects_search_hook');
+register_plugin_hook('unit_test', 'system', 'objects_test'); \ No newline at end of file