$query with multiple custom searches

Skip to first unread message

kevin uittenbosch

May 26, 2014, 10:40:38 AM5/26/14
to ariad...@googlegroups.com
Hi muze,

I have the following scenario when doing a query to find an object and show it.

I have created multiple objects with custom name fields. they are filled with information saved on them when created
    1: selectedOrganization *contains text*
    2: selectedGroup *contains an array*

===== Object 1 (particle)
containing 'selectedGroup' namefield = TEST

===== Object 2 (particle)
containing 'selectedGroup' namefield = TEST * TEST1 * TEST2

Now, when a user logs in, they contain this kind of information so they query is based on the users login

this is how my query looks like:
$query = "object.type='particle' and object.priority>-1 and object.parent = '".$path."' 
and custom:a.name ~='status' and custom:a.value ~='published' 
and custom:b.name ~='selectedOrganization' and custom:b.value ~='".$selectedOrganization."' 
and custom:c.name ='selectedGroup' and custom:c.value =~~ '".$selectedGroup."' 
order by priority asc";

custom:c.name ='selectedGroup' and custom:c.value =~~ '".$selectedGroup."' 

A user contains an array 'selectedGroup'. so Next scenario:

===== User 1

===== User 2

User 1 must see BOTH objects, but can only see object 1 because it's exactly like the string.

User 2 must only see Object 2 but can't because it's not like the string.

How can i do this with the "and custom:c.name ='selectedGroup' and custom:c.value =~~ '".$selectedGroup."' 
I want a needle / haystack query so if an object contains a part of my string it has to display the file.



Auke van Slooten

Jun 4, 2014, 4:02:52 AM6/4/14
to ariad...@googlegroups.com
HI Kevin,

I'm having difficulties understanding the exact problem, however I might have a few pointers.

First, you can simplify the query by using the 'my.*' syntax. Instead of:

and custom:a.name ~='status' and custom:a.value ~='published' 
and custom:b.name ~='selectedOrganization' and custom:b.value ~='".$selectedOrganization."' 
and custom:c.name ='selectedGroup' and custom:c.value =~~ '".$selectedGroup."' 

You can write:

and my.status = 'published'
and my.selectedOrganization = '".$selectedOrganization."'
and my.selectedGroup = '".$selectedGroup."'

In addition the ~= checks only make sense if you use some kind of wildcard in the value, e.g. '%".$selectedOrganization."%'.
The same goes for the =~~ comparison.

If selectedGroup is a custom property with multiple values, the check as written above should be right. If any of the stored values for selectedGroup matches exactly with $selectedGroup, that object should be returned.

If however you store multiple values as a single string in a property, with the values seperated by ' * ', you have a problem. If somehow you need to store multiple values in a single string, you should make sure to start and end the string with the seperation character. In this case instead of storing 'a * b * c', store '*a*b*c*'. This way you can now search for objects with 'a' like this:

and my.selectedGroup ~= '%*a*%'

I hope this answers your question.

Reply all
Reply to author
0 new messages