aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-18 14:40:20 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-18 14:40:20 +0000
commite06d5db3f81d9357329e643b1e3c170d7d47324e (patch)
tree9da2249949cf311c7ebebd319169d895a6b0dcde
parent5c1bc9d2ec9c50710251083355254832097635a0 (diff)
downloadelgg-e06d5db3f81d9357329e643b1e3c170d7d47324e.tar.gz
elgg-e06d5db3f81d9357329e643b1e3c170d7d47324e.tar.bz2
Fixes #41: User full text search. See caveats in function search_for_user()
git-svn-id: https://code.elgg.org/elgg/trunk@967 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--admin/user/index.php6
-rw-r--r--engine/lib/users.php21
-rw-r--r--engine/schema/mysql.sql9
3 files changed, 27 insertions, 9 deletions
diff --git a/admin/user/index.php b/admin/user/index.php
index 4967478c8..947904a0c 100644
--- a/admin/user/index.php
+++ b/admin/user/index.php
@@ -18,12 +18,6 @@
admin_gatekeeper();
- // Display user browser
-
- // if search, perform search
-
-
- // extend user view with ban etc? - Or extend across the board (for admin only)
// Display main admin menu
page_draw(elgg_echo("admin:user"),elgg_view_layout("one_column", elgg_view("admin/user")));
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 16e7a2c5f..50e9d11ea 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -682,6 +682,27 @@
return false;
}
+
+ /**
+ * Searches for a user based on a complete or partial name or username 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.
+ */
+ function search_for_user($criteria)
+ {
+ global $CONFIG;
+
+ $criteria = sanitise_string($criteria);
+ $access = get_access_sql_suffix("e");
+
+ $query = "select e.* from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid where match(u.name,u.username) against ('$criteria') and $access";
+
+ return get_data($query, "entity_row_to_elggstar");
+ }
/**
* Registers a user, returning false if the username already exists
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql
index c981b0a56..749ee5bcf 100644
--- a/engine/schema/mysql.sql
+++ b/engine/schema/mysql.sql
@@ -104,7 +104,8 @@ CREATE TABLE `prefix_objects_entity` (
`title` text NOT NULL,
`description` text NOT NULL,
- PRIMARY KEY (`guid`)
+ PRIMARY KEY (`guid`),
+ FULLTEXT KEY (`title`,`description`)
) ;
-- Extra information relating to "sites"
@@ -116,7 +117,8 @@ CREATE TABLE `prefix_sites_entity` (
`url` varchar(255) NOT NULL,
PRIMARY KEY (`guid`),
- UNIQUE KEY (`url`)
+ UNIQUE KEY (`url`),
+ FULLTEXT KEY (`name`,`description`, `url`)
) ;
-- Extra information relating to "users"
@@ -138,7 +140,8 @@ CREATE TABLE `prefix_users_entity` (
PRIMARY KEY (`guid`),
KEY `password` (`password`),
- FULLTEXT KEY `name` (`name`)
+ FULLTEXT KEY `name` (`name`),
+ FULLTEXT KEY (`name`,`username`)
) ENGINE=MyISAM;