uid); return; case 'delete': search_wipe($user->uid, 'users'); return; } } /** * Implementation of hook_search(). */ function userindex_search($op, $keys = NULL) { switch ($op) { case 'reset': db_query("UPDATE {search_dataset} SET reindex = %d WHERE type = 'users'", time()); return; case 'status': $total = db_result(db_query('SELECT COUNT(*) FROM {users} WHERE status = 1')); $remaining = db_result(db_query("SELECT COUNT(*) FROM {users} u LEFT JOIN {search_dataset} d ON d.type = 'users' AND d.sid = u.uid WHERE u.status = 1 AND (d.sid IS NULL OR d.reindex <> 0)")); return array('remaining' => $remaining, 'total' => $total); } } /** * Implementation of hook_update_index(). */ function userindex_update_index() { $limit = (int)variable_get('search_cron_limit', 100); $result = db_query_range('SELECT u.uid FROM {users} u LEFT JOIN {search_dataset} d ON d.type = "users" AND d.sid = u.uid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, u.uid ASC', 0, $limit); while ($user = db_fetch_object($result)) { _userindex_index_user($user); } } /** * Internal help function to index a single user and optionally it's profile * fields too. * * @todo * Add the possibility for other modules to add to the searchable text by * invoking something like 'update index' in hook_user(). */ function _userindex_index_user($user) { $user = user_load($user->uid); $text = '

'. check_plain($user->name) .'

'; if (module_exists('profile')) { $fields = _userindex_get_profile_fields(); foreach ($fields as $field) { $text .= ' '. $user->$field; } } search_index($user->uid, 'users', $text); } /** * Internal helper function that returns information about all availabe * profile fields. * * @return * Returns an array of all profile fields which values should be indexed. */ function _userindex_get_profile_fields() { static $fields; if (!isset($fields)) { // We dont select date and checkbox fields as their values are hard to // index in a convenient way. $results = db_query('SELECT name FROM {profile_fields} WHERE visibility BETWEEN 2 AND 4 AND type NOT IN ("checkbox", "date")'); while ($field = db_result($results)) { $fields[] = $field; } } return (array)$fields; }