Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Here's a patch that adds a search function for user profiles.
Users with "access user profiles" privileges can search all public profile fields, while users with 'administer users' privileges can search both private and public profile fields.
Search results display username (as a link) along with a snippet of the user's profile.
-Jeff Robbins
Comment | File | Size | Author |
---|---|---|---|
#14 | search_profiles_0.patch | 5.93 KB | Steven |
#13 | search_profiles.patch | 4.28 KB | Steven |
#10 | profile_search.patch | 3.68 KB | Steven |
#9 | profilesearch_1.patch | 1.97 KB | budda |
#8 | profilesearch_0.patch | 1.98 KB | budda |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedprofile.module is only 1 component of the profile page. other modules plug in using hook_user, and i'd like for those same modules to participate in profile search.
this patch is useful still, but i'm hoping we can do better.
Comment #2
jjeff CreditAttribution: jjeff commentedMoshe, are you suggesting some sort of hook that modules would/should implement in order to have their contributions searchable? Say for instance:
I don't really think that there should be separate searches for "user" and "profile", but I'm having a hard time coming up with a good way of creating a SQL call that doesn't make the server cough and sputter... Like for instance, I don't think that all of those ORs above are going to work very efficiently.
Anyone know of a good way to incorporate the SQL stuff in my patch into the SQL for the user search? Is there a way to search for the same thing accross several columns? That would at least unify the searching for user.module and profile.module. (Why are these separate modules anyway?)
Then (if this seems like the right way to go) we can tackle some kind of an additional case in the user_hook to handle injections into the search.
As always, comments are appreciated!
-Jeff
Comment #3
Bèr Kessels CreditAttribution: Bèr Kessels commentedhttp://drupal.org/node/28275 is another approach, as moshe proposes. Allthough It goes far beyond the scope of jsut making sear profiles searchable, it still aims at searchability of *anything*. PLease have a look there, too.
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedComment #5
Steven CreditAttribution: Steven commentedIt would be better to just merge user_search() into profile_search(). user_search() on its own is pretty useless, and to the end-user there should just be a single 'user search'.
Comment #6
Patrick Nelson CreditAttribution: Patrick Nelson commentedJjeff,
Is it possible to have this patch upgraded to work for 4.7? It's really useful and, I suspect, used by quite a few Drupalers.
Regards
Patrick
Comment #7
UncleD CreditAttribution: UncleD commentedI'd like it too!
Comment #8
buddaI've updated the patch to 4.7b4/HEAD.
This adds the search functionality to profile.module under a seperate "profiles" tab on the global search page.
I do agree that it would make sense to have it merged with the 'user' search but didn't want to start on that until somebody decides what is best.
For now I think this patch is a suitable edition to the coming 4.7 release of Drupal and should be included.
I've tested searching profile fields which are both public, restricted, and hidden. Access control is honoured.
Search results correctly display all the profile fields - no matter how many categories there might be. The previous patch had a bug which just returned 'Array' in the search result 'snippet'.
Comment #9
buddaPatch without the SQL wrapped over multiple lines.
Comment #10
Steven CreditAttribution: Steven commenteduntested quickie patch:
- Code style (spacing around operators and foreach)
- Remove user_search()
- Add matching of username to search
I'm slightly worried about performance of the SQL query, needs more testing really.
Comment #11
buddaSteven: what testing procedure do you suggest? I'd like to get this in to profile.module for 4.7 if possible.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedto test this one would need to create some regular profile fields and some admin only profile fields (i.e. hidden). then perform searches with authenticated user and as admin and assure that the correct searches return correct results. non admins can't get hits on admin fields.
also test wildcard searching to verifythat it works as documented
Comment #13
Steven CreditAttribution: Steven commentedI fixed a couple of bugs in the previous patches:
Tested on scratch.drupal.org. The query is quite heavy there (200ms) but for smaller sites it's ideal. I suppose for a dedicated social networking site, you'd need to look towards a more advanced solution.
Comment #14
Steven CreditAttribution: Steven commentedForgot to remove admin/user/search from user.module.
Comment #15
sanduhrsApplied your patch to a fresh CVS install.
It's working fine, but I can't say anything about performance.
vg
Comment #16
mfbWould be fabulous if we could have a search API used by all the user-related contrib modules. For instance, the address module -- part of ecommerce which stores first and last name, address, and phone number -- is not (yet) searchable, as far as I can tell.
Comment #17
buddaUntil/If the search function gets in to profile.module core, i've knocked out a quick module to add searching without the need to keep patching your core profile.module file.
You can find the ProfilePlus module in CVS @ http://drupal.org/node/55469
Comment #18
dmitrig01 CreditAttribution: dmitrig01 commentedI think there is some other issue covering this
Comment #19
moshe weitzman CreditAttribution: moshe weitzman commentedum, this one has a promising patch in it. please demonstrate a better patch before closing this one.
i do much appreciate pruning of the issue queue.
Comment #20
catchComment #21
rcross CreditAttribution: rcross commentedNot sure why this is marked for 7.x - I'm curious if there is the ability to search by more than just username. This seems to do a full text index of the profile - but what about email address or other standard user fields not part of profile.module?
Comment #22
StevenPatzFeatures go into 7.x
Comment #23
Wim LeersThat's right. Back to 7.x.
Comment #24
RobLoachThis post acts as a reminder for me to have a look at this later.
Comment #25
robertDouglass CreditAttribution: robertDouglass commentedNote for later: LOWER is the SQL antichrist:
WHERE LOWER(pv.value) LIKE LOWER('%%%s%%') OR LOWER(u.name) LIKE LOWER('%%%s%%')
so a different solution is desired. Perhaps we should use the search_index table?Comment #26
Wim LeersCleaning up the issue queue.
Comment #27
rcross CreditAttribution: rcross commenteddoes this mean this is committed? or has been otherwise marked won't-fix?
Comment #28
jhodgdonThis issue should not have been closed. However, it is too late for Drupal 7 now.
Comment #29
Damien Tournoud CreditAttribution: Damien Tournoud commentedThe profile module is obsolete. Won't fix.
Comment #30
mfbUser module implements the search hooks, allowing user name (and for admins, also user mail) to be searched. With users being fieldable entities, other user fields should arguably be indexed and searchable.
Comment #31
jhodgdonmfb:
a) This issue is closed, so no one is going to notice your comments here.
b) This issue relates to the profile.module, not to fields on user entities. For what it's worth, the profile module is still a part of D7 core (mostly I think because no one came up with an upgrade path to translate profile module to fieldable user entites).
c) Users are currently not really being indexed for searching. Search users just uses the existing user table to search. If you think fields on user entities should be searchable, that is not a bad idea, but it needs to be filed as a D8 issue, and the way users are currently searchable would need to be overhauled (since the user entities would need to be indexed).