Hi,
Apologies for the delayed response.
I haven’t changed anything significant in the search engine for over a year.
The plugin is at a early stage of development and it needs a lot of new features eg. fuzzy search, faster engine like inverted index, scoring and more.
In the next plugin release I’m going to add new algorithms to improve results sorting. If you can’t wait, try to paste following code into your functions.php. It should solve your problem.
add_filter('dgwt/wcas/search_results/output', 'dgwt_wcas_tmp_improve_relevance');
function dgwt_wcas_tmp_improve_relevance($output){
if(empty($_REQUEST[ 's' ])){
return $output;
}
$keyword = strtolower(sanitize_text_field( $_REQUEST[ 's' ] ));
if(!empty($output[ 'suggestions' ])){
$i = 0;
foreach ($output[ 'suggestions' ] as $suggestion){
$pname = strtolower($suggestion['value']);
similar_text($keyword, $pname, $percent);
$score = $percent;
$pos = strpos($pname, $keyword);
// Add score based on substring position
if ($pos !== false) {
$score += 50; // Bonus for contained substring
// Bonus for substring position
$posBonus = (100 - ($pos * 100) / strlen($pname)) / 2;
$score += $posBonus;
}
$output[ 'suggestions' ][$i]['score'] = $score;
$i++;
}
}
usort($output[ 'suggestions' ], 'dgwt_wcas_tmp_cmp_similarity');
return $output;
}
function dgwt_wcas_tmp_cmp_similarity($a, $b)
{
if ($a['score'] == $b['score']) {
return 0;
}
return ($a['score'] < $b['score']) ? 1 : -1;
}