<![CDATA[ Searching user extended fields - My Forums]]> https://forums.modx.com/thread/?thread=98466 <![CDATA[Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-532545
I now have a membership system working well (using Login extra) on a site I am building out - last step is to create some way of allowing the users of the MODx manager to search the users(members) based on a wide set of criteria.

The user(member) profile includes many extended fields and I need to be able to search all the users and return back relevant users that match the search criteria.

As we all know - the search function in the Manager does not interrogate the extended fields as they are within a JSON string as I understand it...

The search functionality I would like is to include a freeform text input (which would search ALL user fields (standard and extended) and list back the users which match and also a few <select> dropdown menus to allow searching of a few specific extended fields (e.g. location, specialty 1, specialty 2) - again upon setting of these <select> options and hitting the search button - the results should return the users which match the searched criteria.

This searching could either happen in the Manager, or in a page which has AdminOnly access - I am not fussed... think maybe easier to create outside of the Manager maybe?

So...

As I see it from doing some research, I have 2 main options:

1) Find a way to create a search function to search these JSON strings for each user and return the relevant search results. I already have a AdminOnly page fetching and display all the fields (standard and extended) for each user (using pdoUsers) - Can I use simpleSearch / AdvancedSearch to query this data and return results?. I appreciate this might not be the ideal way to do it... but I have spent ages getting the user login / register / update system working and am loathed to start again with it to employ another system of collecting the extended fields info...

2) Use Bob's ClassExtended to extend ModUser (http://bobsguides.com/blog.html/2014/05/27/why-extend-moduser/). I really have no idea how to implement this to be honest, is it a large job to migrate my current working system to use ClassExtender? How does it work with the standard Login extra?

I would favor option 1 due to having the member registration process now working...

Any insight guys? Please bear in mind my PHP is weak at best... so really could do with some hand-holding here! No extended the user to search it before...

P.S. Using pdoUsers: I can return specific users based on a single search/query criteria using the code below:

[[!pdoUsers?
    &groups=`EXAMPLE_GROUP`
    &tpl=`ExampleTpl`
    &sortdir=`asc`
    &limit=`100000`
    &sortby=`id`   
    &where=`{"modUserProfile.extended:LIKE":"%\"examplelocation_01\":\"Bristol\"%"}`
    &showLog=`1`
]]


But, Can I make it so that the "where" element of the code, includes all the user fields, extended and not? If so, then I have half a solution working... Any ideas on hooking this theory up to a search function?

Cheers,

dubbs.]]>
dubbs Oct 01, 2015, 04:11 AM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-532545
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-534442 Quote from: timrca at Nov 15, 2015, 06:42 PM
I struggled with a similar problem, as much as I like using xPDO, I finally broke down and just created an SQL query string that I used to query the table.

It was much easier to develop since I was able phpMyAdmin to build and test the query string. Once I had a query string that gave me the results I wanted, it was just a matter of writing code to plugin the values being sent by the form.

Sounds like an interesting approach - any examples you can share?]]>
dubbs Nov 16, 2015, 03:40 AM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-534442
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-534424
It was much easier to develop since I was able phpMyAdmin to build and test the query string. Once I had a query string that gave me the results I wanted, it was just a matter of writing code to plugin the values being sent by the form.]]>
timrca Nov 15, 2015, 12:42 PM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-534424
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-533049 Quote from: BobRay at Oct 10, 2015, 03:51 AM
I'm afraid I need more to go on. Do you have a user interface created for the search that will let you determine what kind of search it will be? You could post a copy of the form, and a description of what you want to happen based on the submitted results.





OK thanks Bob. I think, I will just leave it as it is for now - if the client wants to change it later I will update on this forum post. Thanks wink]]>
dubbs Oct 12, 2015, 03:57 AM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-533049
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-532977



]]>
BobRay Oct 09, 2015, 10:51 PM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-532977
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-532970 Quote from: BobRay at Oct 09, 2015, 09:18 PM
The first one will always be checked, after that any ANDs will be "anded" with the first one and any ORs will be "orred" with the first one. You can make it more complex, but that will complicate the where statement.

Can you describe what you actually want?

OK thanks, I'd like them to be able to search by 1 or more criteria individually - and also, an option to add criteria together to narrow the search...]]>
dubbs Oct 09, 2015, 04:44 PM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=3#dis-post-532970
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532967
Can you describe what you actually want?]]>
BobRay Oct 09, 2015, 04:18 PM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532967
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532961 Quote from: BobRay at Oct 09, 2015, 05:37 PM
Try changing the ones you want to require from OR: to AND:.

Thanks Bob, so to allow both OR and AND options... I guess I need two forms, one which uses ORs and one which uses ANDs? OR is there some clever way my brain is missing out on here...?]]>
dubbs Oct 09, 2015, 02:59 PM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532961
<![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532954 BobRay Oct 09, 2015, 12:37 PM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532954 <![CDATA[Re: Searching user extended fields]]> https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532897 You know all of this way way better than I wink I am just happy it is working! The only thing missing, is that the freeform textbox, and the 3 selects are connected in OR sequence, so it returns results for any of the 4 search criteria matching a result - what would be supper nice, would be to have an option to make it work in AND sequence as well...

So currently, if you search in the freeform for "Chickens" and then in the 1st select menu for "Red", "Green" in the 2nd and "Purple" in the 3rd - you get members which contain any of the matches for Chickens, Red, Green or Purple - so each member might just match Red for example.

Could I do it so that, the results MUST match ALL the set criteria,

So if you search in the freeform for "Chickens" and then in the 1st select menu for "Red", "Green" in the 2nd and "Purple" in the 3rd - you get members which contain matches for Chickens, Red, Green and Purple - so far fewer members returned in the results as a more strict criteria is set.

Any ideas?

The code I am using for the OR function is:

&where=`[
    {"modUserProfile.extended:LIKE":"%\"[[!Get_value01]]\"%"},
    {"OR:modUserProfile.extended:LIKE":"%\"workregion\":\"[[!Get_Region]]\"%"},
    {"OR:modUserProfile.extended:LIKE":"%\"schoolingphase\":\"[[!Get_SchoolingAge]\"%"},
    {"OR:modUserProfile.extended:LIKE":"%\"subjectsoffered\":\"[[!Get_SubjectsTaught]]\"%"}
]`


With the snippet getting the value searched from the URL string following a <form> GET]]>
dubbs Oct 08, 2015, 03:40 AM https://forums.modx.com/thread/98466/searching-user-extended-fields?page=2#dis-post-532897