We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24629
    • 370 Posts
    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?
      • 3749
      • 24,544 Posts
      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.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 24629
        • 370 Posts
        Hi Bobray,
        thanks for the advise. I figured out TV's are devillish but extending ModResource is even more diabolical,
        It seems i'm stuck between hell and a very hot place smiley
        I also took apart getResources but the whole query stuff is too complex.

        looks like i'm stuck for now.

        RDG
          • 3749
          • 24,544 Posts
          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.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting