Hi, I might be missing something but is there a way to allow users to search through user profiles? If not, I'd be willing to code in the functionality...

thanks.

Comments

moshe weitzman’s picture

please do go ahead and give this a go. When you are ready, this might be a good enhancement to members.module

alex-at-scriptfurnace.com’s picture

I'll get started on this next weekend. Is members.module definitely the right place for this functionality? Should I talk to anyone else before I get started?

dries’s picture

Depends on what is implied by "searching through user profiles". The search module, and thus the search page, can find user accounts but isn't too smart as it will not index profile data (I believe). In fact, both the search module and the profile module could do with being rewritten so there might not be an acceptable fix until that has been taken care of -- and to the best of my knowledge no one is working on either of them. However, if what you want is more like "browsing through user profiles", then the members module is the right place to add this functionality.

alex-at-scriptfurnace.com’s picture

My initial needs are just to be able to select the 'user' checkbox and have the search run against the user profiles. There's different ways to go about doing this, but I imagine the best way is to patch search.module to get it to index user profiles. Further down the line I would like to have a more fine grained search (this would probably go in the members.module) that would allow people to search by location, interests, etc.

eva’s picture

it sounds like what i'd like to do is what you've discussed above. has this functionality been added? i have a series of users that need to be able to search each others' profiles...

thanks,
eva

pluginamp’s picture

Hellow,

this is exactly what I need now too! Is it available yet, in any form? I had thought Drupal would be able to do this, which is part of why I created my site on it...oy...

deeja’s picture

Hi,
Whats the latest on this?
This functionality is exactly what I'm looking for.
Regards

arturoramos’s picture

In the user module, there is a user_search hook function. We can simply add a second sweep through the profile values table to identify any matching strings. It seems to work fine, the only thing is that if a string appears in multiple profile fields, the username gets repeated...

This replaces the function beginning on line 424 of user.module.

function user_search($op = 'search', $keys = null) {
  switch ($op) {
    case 'name':
      if (user_access('access user profiles')) {
        return t('users');
      }
    case 'search':
      if (user_access('access user profiles')) {
        $find = array();
        // Replace wildcards with MySQL/PostgreSQL wildcards.
        $keys = preg_replace('!\*+!', '%', $keys);
        $result = pager_query("SELECT * FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
        while ($account = db_fetch_object($result)) {
          $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid));
        }
        $result = pager_query("SELECT * FROM {profile_values} WHERE LOWER(value) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
        while ($account = db_fetch_object($result)) {
          $result2 = db_query("SELECT * FROM {users} WHERE uid = %d",$account->uid);
          $userinfo = db_fetch_object($result2);
          $find[] = array('title' => $userinfo->name, 'link' => url('user/'. $account->uid));
        }
        return $find;
      }
  }
}
anupam96’s picture

That's pretty good, arturoramos. Works great. Modify the code above to read like the following to fix the repeating problem:

...
          $find[] = array('title' => $userinfo->name, 'link' => url('user/'. $account->uid));
          $find = array_unique($find);
        }
        return $find;
      }
   }
}
mikegull’s picture

Doing array_unique can severely skew the pager_query results. Modify the sql query as follows. (YMMV, note the mysql 4.0/4.1 difference)

        $result = pager_query("select distinct u.* from {users} u left join {profile_values} pv on u.uid=pv.uid where lower(pv.value) like '%%%s%%
'", 15, 0, NULL, $keys); //mysql < 4.1
        //$result = pager_query("SELECT * from {users} where uid in (SELECT uid FROM {profile_values} WHERE LOWER(value) LIKE LOWER('%%%s%%'))
", 15, 0, NULL, $keys);  mysql 4.1??
        while ($userinfo = db_fetch_object($result)) {
          $find[] = array('title' => $userinfo->name, 'link' => url('user/'. $userinfo->uid));
        }
robert castelo’s picture

I've contributed a module which searches username and profile - it's available for Drupal 4.6 now, and being worked on for 4.7....

http://drupal.org/node/58788

Cortext Communications
Drupal Themes & Modules

------------------------------------------
Drupal Specialists: Consulting, Development & Training

Robert Castelo, CTO
Code Positive
London, United Kingdom
----

Ariadoss’s picture

What is the status on the 4.7 module? Is there anything that can be done by anyone to speed up the process of getting it converted? I'm willing to help.
-----
http://www.hogwartslive.com/
http://www.ariadoss.com/
http://www.wizards.pro/

fluitfries’s picture

Just want to save some work for people in the future. There are a few modules being worked on to create a way to search through user profiles. There are also a few hacks, but I am leaving them out of the results. You can find them if you search the forums.

-) Advanced User - http://drupal.org/node/70339
-) Profile Plus - http://drupal.org/node/55469
-) Views Profile - http://drupal.org/node/73245
-) User Search - http://drupal.org/node/66332

Hopefully some or all of the people working on these will come up with a great solution for us!

dado’s picture

http://drupal.org/project/nodeprofile
when it is stable and usable, it would solve the problem by making users into nodes.

surprising that there is still no optimal solution to searching user profiles.
i hope one of these candidates reaches the threshold of usability soon

xamox’s picture

Amen to that, it's getting really annoying not be able to do something that should be built into the core by default. I need this for my site.
---------------------------------------------------------------
http://xamox.NET