Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › User Search and Multiple Keywords
- This topic has 14 replies, 2 voices, and was last updated 7 years, 5 months ago by
lrrm.
-
AuthorPosts
-
December 9, 2018 at 8:35 pm #20327
lrrm
ParticipantHi there,
I have a question about the user search. I have a lot of users with a lot of data, address data and some serialized lists. If I search for an item in a list everything is alright. But if I combine a keyword with an for instance address there are no results. Could it be that this user search just looks for one term?Thanks!
December 10, 2018 at 12:24 pm #20334Ernest Marcinko
KeymasterHi!
With the exception of BuddyPress XProfile fields, all keywords are individually ‘searched’ within each field with each logic. I guess you might be using buddypress fields in this case?
I am not sure if I can change that within the code, mostly because of performance reasons. You could try changing the search logic to ‘OR’, that will give you more results than the default logic though.December 10, 2018 at 3:21 pm #20339lrrm
ParticipantHi Ernesto,
thanks for your reply.
I typed this yesterday evening an re-read it now. For a further explanation: the users are registered with ulitmatemember which isn’t the problem because ultimatemember creates a regular wordpress user and puts some user meta on top.
Some of the custom user meta we added were trainee positions like “computer sciences” or “global health care management” and so on. In total there are around 560 trainee options. For each user we store an individual selection of these 560 trainee positions in the user meta as serialzed data. Each user also has a company name and the companies address (not serialized) stored as user meta fields.
Now if we search for (lets stick to the example) “global health care management” we get all the companies who offer this trainee track. If we use an additional dropdown filter for the cities (which is generated from all the user meta) and enter the search term “global health care management” everything is allright. We get all the companies in the city with this option.
But if we enter “global health care management” AND the same city name in the search input field (without the filter) we get nothing as a result.
I tried to use OR in combination with the two search terms but this gives me either alls results for the city regardless of the trainee position, or all the trainee positions regardless of the city.
Would it be a big problem to change this in the code? I’m not afraid of performance problems because it’s a limited amount of users (regional event) and a limited amount of trainee positions. Maybe with an optional “mayham” checkbox? 🙂
Thanks,
KaiDecember 11, 2018 at 12:00 pm #20349Ernest Marcinko
KeymasterHi Kai,
I have a feeling this should work, since there is no limitation for regular user fields, only buddypress xprofile fields. Can you make sure, that these fields are selected for search on the user search panel here?
December 11, 2018 at 12:46 pm #20351lrrm
Participanthi Ernest, (sorry for mispelling your name first time)
yes, I was convinced that it should work but you can check it yourself.
I’ve attached a file with all the user search settings. “firma_ort” is german and means “company_city”. It’s included.
What do we do now?
Thanks,
KaiDecember 11, 2018 at 1:31 pm #20354Ernest Marcinko
KeymasterThat looks okay to me.
Well, the only possibility left is to debug the query directly. Can you please add temporary FTP access to the site? I will check on the generated query to see what the problem is.
Also, can you share a test search phrase I should try, and which result should come up? That will make it much easier for me.
December 11, 2018 at 2:38 pm #20355lrrm
ParticipantYou cannot access this content.
December 13, 2018 at 12:37 pm #20395lrrm
ParticipantAny news 🙂
December 13, 2018 at 12:39 pm #20396Ernest Marcinko
KeymasterI am working on it at this moment. I might need to setup a test environment, as for some reason everything seems to be okay, yet the query is not returning correctly.
December 13, 2018 at 1:37 pm #20397Ernest Marcinko
KeymasterHi,
I have managed to find a solution, but I am not sure how this will affect the performance, as it requires sub-query usage. I had to make a direct change in one of the search files.
The change I made was in file wp-content\plugins\ajax-search-pro\includes\classes\search\class-asp-search-users.php on line 207 from this:
$parts[] = "( $wpdb->usermeta.meta_key = '" . $meta_field . "' AND ( " . $pre_field . $wpdb->usermeta . ".meta_value" . $suf_field . " LIKE $pre_like'$wcl" . $word . "$wcr'$suf_like ) )";to this:
$parts[] = "EXISTS( SELECT 1 FROM $wpdb->usermeta sums WHERE sums.user_id = $wpdb->users.ID AND sums.meta_key = '" . $meta_field . "' AND ( " . $pre_field . "sums.meta_value" . $suf_field . " LIKE $pre_like'$wcl" . $word . "$wcr'$suf_like ) )";Please make a copy of this, as unfortunately I cannot include this in an upcoming release due to possible performance consequences.
December 13, 2018 at 2:33 pm #20398lrrm
ParticipantI am working on it at this moment. I might need to setup a test environment, as for some reason everything seems to be okay, yet the query is not returning correctly.
These are the best behaviours. 😀 😀 😀
Ok, then I will make a backup and reinstantiate this when it when an update was made. I understand that you can’t include it by default but would it be possible to have a checkbox to enable it? Probably the problem occurs somewhere else and so there would be a solution before someone asks.
Thank you very much!
December 13, 2018 at 3:41 pm #20399Ernest Marcinko
KeymasterHi,
I thought of possible solution. I have added an additional query argument, that can be changed via a custom hook within the function.php file. So I changed the files, and I will include this change in the upcoming release as well, so you don’t have to overwrite it every time.
Just keep this custom code in your theme functions.php file, and it will work without any changes:
add_action('asp_query_args', 'asp_query_args_meta_changes'); function asp_query_args_meta_changes($args) { $args['user_search_meta_fields_separate_subquery'] = 1; return $args; }December 13, 2018 at 3:46 pm #20400lrrm
ParticipantYou are the HERO of the day! Thank you very very much! 🙂
December 13, 2018 at 3:49 pm #20401Ernest Marcinko
KeymasterYou cannot access this content.
December 13, 2018 at 3:52 pm #20402lrrm
ParticipantYes, mark it as resolved. I will rate it very positivly 🙂
-
AuthorPosts
- The topic ‘User Search and Multiple Keywords’ is closed to new replies.