Posted on

Results are in strange order

If best results don’t come up first and changing weighting settings doesn’t seem to make any difference, there couple of things you can do.

Is Relevanssi active?

The first thing is to check if the results are actually provided by Relevanssi. If you disable Relevanssi, do the results change? Do you see Relevanssi-generated excerpts? There are different reasons why your search results may not come from Relevanssi even if Relevanssi is activated, and the most common has to do with query posts calls. For that, see this Knowledge Base entry.

Are the results in menu_order?

I’ve seen several cases where odd search results are caused by a theme (or a plugin) that forces the search to use menu_order, for some reason. If that’s the problem, the solution is simple. Add this code to your theme functions.php:

add_filter( 'relevanssi_orderby', function ( $orderby ) { return 'relevance'; } );

3 comments Results are in strange order

  1. After debugging for hours I found you need to make sure your functions.php doesnt have;

    add_filter(‘facetwp_use_search_relevancy’, ‘__return_false’);

    AND

    function [theme_name]_facetwp_alter_sort_options($options, $params) {
    return [];
    }
    add_filter(‘facetwp_sort_options’, ‘ [theme_name]_facetwp_alter_sort_options’, 10, 2);

    Both of these will skip the Relevanssi sorting

  2. I did this:

    add_filter( ‘relevanssi_orderby’, function ( $orderby ) { return ‘relevance’; } );

    And it took down my entire website! Currently on line to tech support to try and restore it. But I politely suggest this instruction for NOT be followed.\

    Jon

    1. Jon, the tech support will find out there’s a typo in the code. The code itself cannot do harm like that, but a smallest typo – a missing brace, for example – can crash a site.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *