Hello,
I'm trying to implement the search hook in a very simple block module that only adds a directory of all users with the role "doctor" and a search tab for finding only users with the doctor role. So the weird thing is that it works but only for some users and not others.
"dobson" and "marigold" are both doctors for example. Dobson does not come up, but marigold does get retrieved by the search.
The SQL query works for ALL users when I enter it directly into MySql's command line, so it can be the SQL query in and of itself. The only space for variation is in the $keys parameter which is clearly working for the other users.
Also, I am doing the search as the root drupal administrator so it can't be that I am restricted to not be aware of that one user (dobson).
Below is the search hook implementation I wrote. Any comments or suggestions are greatly appreciated! -Rob
function doctor_update_index() {
// do nothing. We do not want anything indexed
}
function doctors_search($op = 'search', $keys = NULL) {
global $user;
switch($op) {
case 'name': $results = t('doctor');
break;
case 'search':
$results = array();
$q = "select distinct u.uid, u.name from {users} u, {users_roles} ur, {role} r " .
"where u.uid=ur.uid and ur.rid=r.rid and r.name='doctor' and" .
"(u.name LIKE '%" . $keys . "%')";
$r = db_query($q);
while ($usr = db_fetch_object($r)) {
$results[] = array('link' => '?q=user/' . $usr->uid, // link to node for USER
'snippet' => '',
'title' => $usr->name
);
}
break;
case 'reset':
variable_del('node_cron_last');
break;
case 'status':
$results = array('remaining' => 0, 'total' => 0);
break;
}
return $results;
}
function doctors_search_item($item) {
$o.= '
';
$o.= l($item['title'], $item['link']) . '