Skip to main contentSkip to footer

On one of our sites we have 2 search boxes, one where you can do a normal search and the other where you can search for employees or departments. The employees/department search is done by using the relevanssi_do_query() function.

Can we use fuzzy matching on the normal search and disable it on the employees/department search?

Yes, you can, but it takes some hacking. Since Relevanssi has just one setting for the fuzzy search, you need to change it on the fly for one of the searches. It’s probably easier to do with the relevanssi_do_query() search.

Relevanssi reads the fuzzy search setting from the relevanssi_fuzzy option. WordPress provides you with pre_option_relevanssi_fuzzy filter you can use to change the value. The values are “always” and “sometimes”, and everything else counts as none. So, set the setting to always from Relevanssi settings, and then add a filter function that sets the value to, for example, “none” when you’re doing an employee/department search.

For example, you can set a global variable before the relevanssi_do_query(), like this:

global $relevanssi_disable_fuzzy;
$relevanssi_disable_fuzzy = true;
relevanssi_do_query( $args );

Then use that global variable as a trigger:

add_filter( 'pre_option_relevanssi_fuzzy', 'rlv_disable_fuzzy' );
function rlv_disable_fuzzy( $value ) {
    global $relevanssi_disable_fuzzy;
    if ( $relevanssi_disable_fuzzy ) $value = "none";
    return $value;
}

The pre_option_ filter hooks are, in general, a mighty powerful tool to know.

Your account

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

Search

Popular Resources

Toolset Views

…you’d expect. Because of the way the Toolset Relevanssi compatibility is built, the query variables are not passed to Relevanssi from the search query like they are when Toolset is not involved. This may lead to confusion, when adding a query variable (for example &post_types=page) to the URL has no……effect on the results, even though you can tell for sure the search is powered by Relevanssi. The reason is simple: Relevanssi doesn’t see that query variable, because Toolset does not pass it to Relevanssi. Fortunately Toolset provides means to fix this. There’s a filter hook you can use to…

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