diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-18 15:12:15 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-18 15:12:15 +0000 |
commit | af3899ff2049706349a88d9e60a0dd7940ab7587 (patch) | |
tree | 3fc16c092f1e4b30eee8d755813693cdfc476179 /engine/lib | |
parent | 036fec5442590dfb61d88afa5b9154c48037cb17 (diff) | |
download | elgg-af3899ff2049706349a88d9e60a0dd7940ab7587.tar.gz elgg-af3899ff2049706349a88d9e60a0dd7940ab7587.tar.bz2 |
Fixes #42: Object full text search on description
git-svn-id: https://code.elgg.org/elgg/trunk@969 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/objects.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/engine/lib/objects.php b/engine/lib/objects.php index 7c14e8cee..efe7f6dec 100644 --- a/engine/lib/objects.php +++ b/engine/lib/objects.php @@ -289,6 +289,50 @@ }
return false;
+ } + + /** + * Searches for an object based on a complete or partial title or description using full text searching. + * + * IMPORTANT NOTE: With MySQL's default setup: + * 1) $criteria must be 4 or more characters long + * 2) If $criteria matches greater than 50% of results NO RESULTS ARE RETURNED! + * + * @param string $criteria The partial or full name or username. + * @param int $limit Limit of the search. + * @param int $offset Offset. + * @param string $order_by The order. + * @param boolean $count Whether to return the count of results or just the results. + */ + function search_for_object($criteria, $limit = 10, $offset = 0, $order_by = "", $count = false) + { + global $CONFIG; + + $criteria = sanitise_string($criteria); + $limit = (int)$limit; + $offset = (int)$offset; + $order_by = sanitise_string($order_by); + + $access = get_access_sql_suffix("e"); + + if ($order_by == "") $order_by = "e.time_created desc"; + + if ($count) { + $query = "SELECT count(e.guid) as total "; + } else { + $query = "SELECT e.* "; + } + $query .= "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where match(o.title,o.description) against ('$criteria') and $access"; + + if (!$count) { + $query .= " order by $order_by limit $offset, $limit"; // Add order and limit + return get_data($query, "entity_row_to_elggstar"); + } else { + if ($count = get_data_row($query)) { + return $count->total; + } + } + return false; }
/**
|