Hi,
i need to build a small 'searchengine'. It needs to be able to search through all resources with several AND and OR queries mixed. hard stuff that is.
So i'm trying to make it a bit more flexible for myself by running several modx->query 's.
How can i search through a previous found collection. example
col1 = find all resources that have Mytv1 = 'whatever'
next do a search through col1 and find all resources that have MyTv2 = 'something else', call it col2
next search through col2 find all resources that have the word 'Help' in either pagetitle or content.
it has something to do with subqueries but i don't know how.
I was hoping something like this would work.
$criteria = $modx->newQuery('modResource');
$criteria->where(array(
array(
'template' => 4,
'published' => 1,
'deleted' => 0
),
array(
Mytv1:AND=>'whatever',
array(MyTv2:AND =>'something else',
array(
'pagetitle:LIKE' => '%HELP%',
'OR:content:LIKE' => '%HELP%'
),
),
),
));
$docArray = $modx->getCollection('modResource', $criteria);
Any ideas how to do this?
TV queries are devilish because the information is in several different places. You can do a join on the modTemplateVarResource table, but the problem is that TVs set to their default values have no record there. A TV's default value is in the modTemplateVar table. That's the main reason for extending the modResource object. Once you do that, searching and sorting become much faster and easier.
If you must use TVs for this, take a look at the getResources code that handles TV filters.
I'm currently working on an extra that will extend modUser and/or modResource (
https://github.com/BobRay/ClassExtender) for you.
It's in transition right now to a version with forms to make it much easier to use. I expect to do some new commits in the next few days.