From 5f956688562eac1ae1131e964cc83e17092b89e7 Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 18 Jun 2008 15:15:51 +0000 Subject: Fixes #43: Site full text search over name, description and url git-svn-id: https://code.elgg.org/elgg/trunk@970 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/sites.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'engine/lib') diff --git a/engine/lib/sites.php b/engine/lib/sites.php index 9d81c7364..fe8a23cf1 100644 --- a/engine/lib/sites.php +++ b/engine/lib/sites.php @@ -500,7 +500,49 @@ return false; } - + /** + * Searches for a site based on a complete or partial name or description or url 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_site($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}sites_entity s on e.guid=s.guid where match(s.name,s.description,s.url) 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; + } /** -- cgit v1.2.3