apply_filters( 'relevanssi_exact_match_bonus', array $bonus )

Adjusts the bonus weights for exact matches.


(array) The bonus weight multipliers. The bonus for title matches is in the index title, the bonus for content matches in content. Default array( 'title' => 5, 'content' => 2 ).

More information

In order to keep the Relevanssi settings page lean, this setting has been made into a filter hook. You can enable the exact match bonus from the settings page, and if necessary, adjust the weights with the filter hook.

If you want to make the exact matches more significant, you can do this in your theme functions.php:

  function() {
    return array( 'title' => 10, 'content' => 5 );

The way the exact match bonus works is that if the setting is enabled, Relevanssi will look in the post title and content for the search query (with possible phrase quotes removed) and if there’s a match using stristr(), the weight of the match is multiplied by the bonus.

The exact match bonus does not look inside anything else than titles and content, and like phrase matching won’t understand if the post content has HTML tags in it. If you’re searching for “black cat”, “black <strong>cat</strong>” won’t count as an exact match.

To give a bonus for exact matches in custom fields, you can use this function:

add_filter( 'relevanssi_results', function( $doc_weight ) {
    $query  = relevanssi_remove_quotes( get_search_query() );
    $fields = relevanssi_get_post_meta_for_all_posts( array_keys( $doc_weight ), 'field_name' );
    foreach( $doc_weight as $doc_id => $weight ) {
        if ( isset( $fields[ $doc_id ] ) && relevanssi_mb_stristr( $fields[ $doc_id ], $query ) !== false ) {
            $doc_weight[ $doc_id ] *= 10;
    return $doc_weight;
} );