aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-18 15:15:51 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-18 15:15:51 +0000
commit5f956688562eac1ae1131e964cc83e17092b89e7 (patch)
tree57172674fe69cfb6beb93cd417429a3653218150
parentaf3899ff2049706349a88d9e60a0dd7940ab7587 (diff)
downloadelgg-5f956688562eac1ae1131e964cc83e17092b89e7.tar.gz
elgg-5f956688562eac1ae1131e964cc83e17092b89e7.tar.bz2
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
-rw-r--r--engine/lib/sites.php44
1 files changed, 43 insertions, 1 deletions
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;
+ }
/**