We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    I'm trying to make AdvSearch only match whole words as this is a request of my client. I've tried a lot of different ways of doing this, including altering the sql query to match for the search term with spaces before, after or around the word. But this isn't a usable solution, because some instances of the search term won't be found this way (for example if the word is the only word in a field, like 'Contact' as a pagetitle).

    I also tried to use REGEXP instead of LIKE in the search query, but this doesn't seem to be working as well (all results are returned). Now I'm trying to filter the results with a queryHook. I hope that's even possible!

    This is what I've got so far:

    <?php
    
    $andConditions = array(
            'pagetitle:REGEXP:%[^a-z]{1}[^a-z]%' => 'zoekterm:request',
            'OR:introtext:REGEXP:%[^a-z]{1}[^a-z]%' => 'zoekterm:request',
            'OR:content:REGEXP:%[^a-z]{1}[^a-z]%' => 'zoekterm:request'
    );
    
    $qhDeclaration = array( 
     'qhVersion' => '1.2', // version of queryHook - to manage futures changes 
     'andConditions' => $andConditions, 
    ); 
    
    $hook->setQueryHook($qhDeclaration);
    
    return true;


    I also tried just this:

    <?php
    
    $andConditions = array(
            'pagetitle:REGEXP:%[^a-z]{1}[^a-z]%' => 'zoekterm:request'
    );
    
    $qhDeclaration = array( 
     'qhVersion' => '1.2', // version of queryHook - to manage futures changes 
     'andConditions' => $andConditions, 
    ); 
    
    $hook->setQueryHook($qhDeclaration);
    
    return true;


    It's not working, it results in an error (blank screen, server error message).

    I'm guessing the syntax for the regexp is wrong, or the way I'm trying to get the GET param (zoekterm:request). However this is what I could make of the documentation. I really hope someone can give me a hint here! Thanks!