Currently you cannot search the profile fields of the users.

I added a "real name" field and people kept getting zero results for their searches. Not good.

Introducing a _search hook was the way to enable sarching. I have chosen to rather extend the search hook of user hook than adding a search hook to profile.module. Because if I had added it to profile.module you would have the option to either search for users of for profiles which does not make sense at all.

CommentFileSizeAuthor
#4 profile_search.diff1.07 KBwalkah
user_1.patch1.17 KBkilles@www.drop.org

Comments

TDobes’s picture

+1... excellent idea

dries’s picture

First, this patch is a bit hack-ish in that it operates on the profile module's internal structures.

Secondly, it does not respect the profile fields' 'private'-setting.

killes@www.drop.org’s picture

The use of profile module's internal structure is perfectly valid as this is where the sought values are to be found.

The privacy setting in its current form is pretty useless anyway:
http://drupal.org/node/view/9798

The proper solution would be to put the privacy setting into the profile module's db structure maybe using the new access patch (if possible). It would be relatively easy to make a setting visible on a per role basis for example. Unfortunatelxy I don't have time for it.

walkah’s picture

Assigned: killes@www.drop.org » walkah
StatusFileSize
new1.07 KB

i think this is very important since end users don't understand why profile information doesn't create search hits.

i also agree that making use of profile internals is acceptable here since profile data is really an extension of user info.

attached is an updated patch (against HEAD) that a) repsects private fields and b) ensures distinct results.

moshe weitzman’s picture

+1 for the functionality. -1 for the implementation.

Any module can add profile data via hook_user(), not just profile.module. So to be consistent, I propose a new operation in hook_user() where modules return search results.

Orofile.module will then use this hook to append matching users as needed. This will fix the problem where user.module acts upon data maintained in profile.module. Its OK that profile table is accessed during a search. Its not OK that user.module is doing the accessing. Just my .02.

walkah’s picture

good point, however, with the 4.5 freeze on and rumblings of search.module overhauls for 4.6, this is a quick fix that catches the main case, i.e. profile.module -- which is part of core.

i'd say this patch is still worth it for 4.5... but i guess it's in Dries' hands ;)

Bèr Kessels’s picture

+1 from me.
I think, that this might sound like a "quick hack". I would rather call it a "temporary solution". Indeed we would need a general approach, but thats the case in much more places in Drupal. Untill someone rewrites big parts to create such a "general apporach" the best solution acc. to me, is a solution that at least fixes thing so it does what users expect: return profile info.

Ber

moshe weitzman’s picture

my goal for searchable profiles would be for fielded search. htat is a criiteria builder where you could select 'male' and 'single', for example. the criteria builder ui is dynamic depending on the active profile fields.

Anonymous’s picture

Sorry to barge in - would any of you esteemed Drupal folk care to help mentor me through implementation of a field level profile search? - I need one for a client.
I've only just started looking at Drupal API's etc. so it feels like a challenge, but that's how to get to know a system like this is it not?.... your the team in the know, if you can spare a moment, and perhaps a guiding light or two, here are my initial (sketched) thoughts:
http://drupal.org/node/12568

Thankyou.

Anonymous’s picture

ps. My phase two (as described in above mentioned node) is to provide the dynamic aspect so eloquently described by Weitzman.

killes@www.drop.org’s picture

The issue is very important, but unfortunately the patch does not apply anymore.

Steven’s picture

I'm not convinced of the use of a user-specific search hook. Really, it would be quite complicated, and profile.module is already the swiss army knife of user data.

We could just move the user search directly into profile.module. The only downside to that is that you need profile.module just to search users. This is IMO an acceptable compromise, as the current search is just a stupid wildcard match on the username. I.e. it doesn't help you find people, it helps you find usernames.

About indexing: we could use the text indexing for users as well, but I'm not sure it would be very useful. There wouldn't be much scaling benefits as every user's profile is typically short and to the point, not like a piece of text.

dublin drupaller’s picture

would the following woprkaround be acceptable?

1 An extra checkbox underneath the serach box that says something like "user profile information".

2 an extra option on the SEARCH settings page that allows admin the ability to switch on/off the extra checkbox.

I was looking for such a patch earlier (to search profiles) and noticed the discussion sorta died.

The latest patch linked above worked first time for me (drupal 4.5) for anyone else looking for a solution.

I notice that the search does take a little bit longer than normal though..after installing the patch which is understandable. So perhaps the above idea (make search user profiles information optional) might rekindle the discussion/patch.

Dub

Steven’s picture

-1 on the checkbox. Like Google, we try to give the user the best possible search without fuss. E.g. when nothing is found, search automatically adds wildcards to the query and tries again.

killes@www.drop.org’s picture

So, do we agree that we want to move user-search to profiles? Or not? Dries?

RobRoy’s picture

What's going on with this? I'm using this quickfix, but definitely think this should be included in users or profiles module. I actually wanted users to be able to find other members according to what exact options they chose in their profiles. Like when you click on a link in a user's profile, it shows other users who match that option, but I want people to be able to search all users on all options (find other users who like movies, or books, or whatever) and have it be a little more interactive then just a search box. Has anyone started that or should I?

If anyone needs this quick fix for 4.6, I think you just replace this in users.module

        $keys = preg_replace('!\*+!', '%', $keys);
        $result = pager_query("SELECT * FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);

with this

        $keys = preg_replace('!\*+!', '%', $keys);
        // start mod
	if (module_exist('profile')) {
  		$result = pager_query("SELECT DISTINCT(u.uid), u.name FROM {users} u 
						LEFT JOIN {profile_values} p ON p.uid=u.uid 
						LEFT JOIN {profile_fields} f ON f.fid=p.fid 
						WHERE LOWER(u.name) LIKE '%%%s%%' 
							OR (LOWER(p.value) LIKE '%%%s%%' 
							AND f.visibility != %d)", 15, 0, NULL, $keys, $keys, $keys, PROFILE_PRIVATE);
		}
		else {
			$result = pager_query("SELECT * FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
		}
		// end mod
moshe weitzman’s picture

rbarreca. you should work on this. many have promised to deliver this but never did.

joerique’s picture

Hi folks,

I've tried the above code, it sure searches inside profiles, but with a strange side effect - it no longer allows the users to edit their own settings (with the exception of admin). Please advise on how to avoid this.

TIA,
Joe.

kevinc-1’s picture

Category: task » bug

I have the same issue. When I use the code above I get the same issue. The profile fields are searchable, but it is not possible to change any of the fields - a blank page results when I try to save.

Please help!

Kevin D. Clarke
email: kdc01@rogers.com
surf: http://www.theengine.com/
surf: http://www.GayInRealLife.com/

kevinc-1’s picture

Correction. The field valuse ARE saved, but I still get the blank page. Your assistance is apprieciated.

kbahey’s picture

Status: Active » Closed (duplicate)

Here is a more recent issue with a patch http://drupal.org/node/32382