Skip to main contentSkip to footer

My Relevanssi engine has the AND operator enabled, with a fallback to OR when the search finds no matches. I’d like the search to display first the AND results and later the OR results.

For example, if I search for “wedding party”, I’d like the search to show first the entries matching both words and later the entries matching only “wedding” or only “party”.

Is it possible to configure or program a search like that?

What you’re asking for is pretty much what the OR search aims to do. It’s not strict, though, so if some post seems to be valuable even if it doesn’t have all the search terms, it will be high on the list, but most of the time if all search terms are good search terms, AND matches will be on the top.

If you really want to push it further, perhaps something like this with the relevanssi_match filter hook:

add_filter( 'relevanssi_match', 'rlv_and_boost' );
function rlv_and_boost( $match ) {
    global $rlv_and_database;
    $multi_term_boost = 5;
    if ( ! isset( $rlv_and_database[ $match->doc ] ) ) {
        $rlv_and_database[ $match->doc ] = true;
    } else {
        $match->weight *= $multi_term_boost;
    }
    return $match;
}

With this function in place, posts that match more than one search term will get a bonus. The more search terms the post matches, the bigger the bonus. You can adjust the boost factor until you get results you like.

This was asked here.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Debugging Relevanssi searching issues

…restrictions involved? Look at the results add_filter( ‘relevanssi_results’, ‘rlv_check_results’ ); function rlv_check_results( $results ) { var_dump( $results ); exit(); } This should print out an array of ( post ID, post weight ) pairs. Does that match the number of results you expect to find? Look at the posts returned…Relevanssi has plenty of useful filter hooks you can use to debug problems. Here are some examples of how you can use the Relevanssi filter hooks to debug issues. Add the functions one at a time to your site and run a search to see results. First, try the Relevanssi……admin search. Before checking the filters, try the Relevanssi admin search (Dashboard > Admin search). Does that find the correct results? If it does, then the problem is likely with your theme. Use Query Monitor Query Monitor is a superb tool for debugging WordPress behaviour. It’s very useful for debugging…

WooCommerce: Hidden products in search

Relevanssi by default shows out-of-stock and excluded from catalogue WooCommerce products in the search results, but hides those set to excluded from search (before 2.2.2 and 4.1.2 the default behaviour was to show all products). It is quite easy to make Relevanssi not display hidden products in the results. The…products from the search. This method leads to much faster indexing times. Add this to your site: add_filter( ‘relevanssi_woocommerce_indexing’, ‘rlv_woocommerce_filter’ ); function rlv_woocommerce_filter( $blocks ) { $blocks[‘outofstock’] = true; $blocks[‘exclude-from-catalog’] = true; $blocks[‘exclude-from-search’] = true; return $blocks; } There’s one key for each product visibility level, set the ones you……), ‘product_visibility’, $post_id ) ) { $block = true; } return $block; } This code will unindex products that are set to be excluded from the catalogue, excluded from search or that are out of stock. If you want to keep out of stock items in the search results, just…

Genesis
In some cases, Relevanssi requires modifications to the search result template for the search results to work properly (in particular…

Related Posts:

Comment Section:

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed