No idea if anyone has done this before, but couldn’t find any reference when I searched the forums.
When searching for text such as ’Rob’, the highlighting would only highlight the actual word, whereas I wanted it to highlight variations such as ’rob’ and ’ROB’ as well. Inserting the code below at line 838 within the file
/assets/snippets/ajaxSearch/classes/search.class.php does the trick. This is for version 1.8.0 of ajaxSearch.
$finalExtract = preg_replace( '/' . preg_quote( strtoupper($searchTerm), '/' ) . '/' .$this->pcreModifier, '<span class="'.$highlightClass.' '.$highlightClass.$count.'">\0</span>', $finalExtract);
$finalExtract = preg_replace( '/' . preg_quote( strtolower($searchTerm), '/' ) . '/' .$this->pcreModifier, '<span class="'.$highlightClass.' '.$highlightClass.$count.'">\0</span>', $finalExtract);
$finalExtract = preg_replace( '/' . preg_quote( ucfirst($searchTerm), '/' ) . '/' .$this->pcreModifier, '<span class="'.$highlightClass.' '.$highlightClass.$count.'">\0</span>', $finalExtract);
A nice little modification to the code, perhaps this could become a parameter in future.
For those coding purists, the above was replaced with:
// highligth the search terms if needed
if ($this->cfg['highlightResult']){
$count = 1;
foreach($searchList as $searchTerm){
$sArray = array();
$sArray[] = '/' . preg_quote( $searchTerm, '/' ) . '/' .$this->pcreModifier;
$sArray[] = '/' . preg_quote( strtoupper($searchTerm), '/' ) . '/' .$this->pcreModifier;
$sArray[] = '/' . preg_quote( strtolower($searchTerm), '/' ) . '/' .$this->pcreModifier;
$sArray[] = '/' . preg_quote( ucfirst($searchTerm), '/' ) . '/' .$this->pcreModifier;
$rArray = array_fill(0, count($sArray), '<span class="'.$highlightClass.' '.$highlightClass.$count.'">\0</span>');
$finalExtract = preg_replace( $sArray, $rArray, $finalExtract);
$class .= ' '.$highlightClass.$count;
$count++;
}
}