--- profile.module-old	2006-01-31 14:42:42.000000000 +0000
+++ profile.module	2006-02-01 15:06:11.077632512 +0000
@@ -566,6 +566,52 @@
   }
 }
 
+function profile_search($op = 'search', $keys = null) {
+  switch ($op) {
+    case 'name':
+      if (user_access('access user profiles')) {
+        return t('profiles');
+      }
+    case 'search':
+      if (user_access('access user profiles')) {
+        $find = array();
+        // Replace wildcards with MySQL/PostgreSQL wildcards.
+        $keys = preg_replace('!\*+!', '%', $keys);
+        if (user_access('administer users')) {
+          // administrators don't have restrictions
+          $result = pager_query("SELECT u.* FROM {users} u INNER JOIN
+{profile_values} pv ON u.uid = pv.uid INNER JOIN {profile_fields} pf ON
+pv.fid = pf.fid WHERE LOWER(pv.value) LIKE LOWER('%%%s%%')", 15, 0, NULL,
+$keys);
+        }
+        else {
+          // non-administrators can only search public fields and active users
+          $result = pager_query("SELECT u.* FROM {users} u INNER JOIN
+{profile_values} pv ON u.uid = pv.uid INNER JOIN {profile_fields} pf ON
+pv.fid = pf.fid WHERE LOWER(pv.value) LIKE LOWER('%%%s%%') AND
+pf.visibility IN (%d, %d) AND u.status = 1", 15, 0, NULL, $keys,
+PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
+        }
+
+        while ($account = db_fetch_object($result)) {
+          $user = user_load(array('uid'=>$account->uid));
+          $profile_fields = profile_view_profile($user);
+
+          $entry = array();
+          foreach($profile_fields as $category => $fields) {
+            foreach($fields as $field) {
+              $entry[] = $field['value'];
+            }
+          }
+
+          $view = implode(' | ', $entry);
+          $find[] = array('title' => $account->name, 'link' => url("user/$account->uid/view"), 'snippet' => search_excerpt($keys, $view));
+        }
+        return $find;
+      }
+  }
+}
+
 function _profile_field_form($type, $edit = array()) {
 
   $form['fields'] = array('#type' => 'fieldset',
