WordPress.org

Forums

Relevanssi - A Better Search
[resolved] better relevance_score (3 posts)

  1. AliMH
    Member
    Posted 9 months ago #

    hey mikko,
    first really thanks for your plugins,it's awesome.
    my only remaining problem is relevance_score.
    if you check this link http://animup.net/?s=one+piece&post_types=animes&types=anime&orderby=relevance_score&order=DESC
    you can see that topic with exactly "One piece" in title come in 21's result. is there anyway to to make it first?

    https://wordpress.org/plugins/relevanssi/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  3. AliMH
    Member
    Posted 9 months ago #

    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;
    }

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.