WordPress.org

Support

Support » Plugins and Hacks » [Resolved] better relevance_score

[Resolved] better relevance_score

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari
    Participant

    @msaari

    The problem is, nothing makes that post more valuable than the other posts above it, all of which mention “One piece” in the title as well. The one on top actualle mentions “One Piece” twice in the title, which makes it appear twice as significant.

    If you want to make exact match titles like this appear on top of the results, you need to force it. relevanssi_hits_filter gives you all the tools you need: it gives you an array of search results and the search term. You can go through the results and if the title matches exactly to the search term, move that post first in the results.

    There are some examples in the user manual.

    really thanks,
    here is my wroking code:

    function order_the_results($hits) {
        global $wp_query;
    	$search=strtolower($wp_query->query['s']);
    	$i=0;
    	foreach ($hits[0] as $hit){
    		if ($search == strtolower($hit->post_title)){
    			unset($hits[0][$i]);
    			array_unshift($hits[0] , $hit);
    		}
    		$i++;
    	}
    	return $hits;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] better relevance_score’ is closed to new replies.