We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30585
    • 833 Posts
    I never thought I'd learn anything xPDo, but here I am playing in a minefield and learning a thing or two in the process.

    Anyway, I have a custom table from which I'm pulling data using a custom search snippet. I'd like to take things a step further and do a full-text search. But I'm stuck and given my very limited knowledge in the subject, I was hoping someone could lend a hand.

    The solution most likely resides in this post: https://forums.modx.com/index.php?topic=61256.0 but I just couldn't apply it successfully.

    Here's a portion of my search snippet (which is loosely based on another snippet posted somewhere in the forums)
    <?php
    $get = normalize_str($get);
    
    $output ='';
    
    if ((isset($get)) || (isset($session))) {
    
        $search = $get;
        //if (isset($search)) {$session = $search;};
        //echo '<p>Session search = ' . $get . '</p>';
    
        $c = $modx->newQuery('BibleVerse');     
        $c->bindGraph('{"Book":{}}'); // Without this, getCount fails. Order is important
        $c->where(array(
        'book:LIKE' => '%' . $get . '%',        
        'OR:chapter:LIKE' => '%' . $get . '%',
        'OR:verse:LIKE' => '%' . $get . '%',
        'OR:Book.book:LIKE' => '%' . $get . '%',    
    	'OR:lsg:LIKE' => '%' . $get . '%',
    	));
        
        $total = $modx->getCount('BibleVerse', $c);
        //echo '<p>Total records found: ' . $total . '</p>';
     	
        //set search string placeholder    
        $modx->setPlaceholder('string', $get);
    
        //set "total" placeholder for getPage
        $modx->setPlaceholder($totalVar, $total);
      
        //&limit, &offset
        if (!empty($limit)) {
            $c->limit($limit, $offset);
        }
    
        //run query and loop through the results
        //Book is the alias for the BibleBook class
        if ($results = $modx->getCollectionGraph('BibleVerse', '{"Book":{}}', $c)) {
            foreach ($results as $result) {
                $fields = $result->toArray();  
                $fields[versebook] = $result->Book->get('book');          
                $rows[] = $modx->getChunk($tpl, $fields);
            }
      
            $ph['rows'] = implode('', $rows);        
            $output = $modx->getChunk($tplouter, $ph);
      
        } else {
            $output = $noresults;
        }
    }
    return $output;
    ?>


    UPDATE: I added
    $c->bindGraph('{"Book":{}}');
    Without it, getCount was failing.

    In MySQL, I could do the following to perform a full-text search in one table.
    SELECT * FROM modx_bible_verses
     WHERE MATCH (book,chapter,verse,lsg) AGAINST ('1 Samuel 22' IN BOOLEAN MODE);

    How could I do this with xPDO, given that I have two related tables?

    in the string above, the '1 Samuel 22' portion should be pulled from Bible.book and 22 from BibleVerse.book [ed. note: treigh last edited this post 12 years, 6 months ago.]
      A MODx Fanatic
      • 30585
      • 833 Posts
      Anyone?
        A MODx Fanatic