ElasticPress & WooCommerce: Deactivate Product Search Fuzziness

I am a great fan of Elastic Search, the ElasticPress plugin and the ElasticPress WooCommerce module. The other day, when I was working on a clients WooCommerce shop, it was the first time I wasn’t satisfied with the quality of the search results, though.

After some digging with the Debug bar and its ElasticPress extension, I could narrow down the problem to a combination of many resembling titles in our database and the Elastic Search fuzziness parameter. Of course the fantastic folks at 10up provide a filter for that in their ElasticPress plugin.

 

So here is how to disable fuzziness in the search:

function themeslug_deactivate_ep_fuzziness( $fuzz ) {
    return 0;
}
add_filter( 'ep_fuzziness_arg', 'themeslug_deactivate_ep_fuzziness' );

Of course you can even raise the fuzziness with the same method. If you want to adjust fuzziness dependent on other search parameters, the filter provides two more arguments, $search_fields and $args, which might help.

Recommendation: If you want to use WordPress with ElasticSearch, you can get both with Kinsta. Read more on how to speed up WordPress with their ElasticSearch solution on the Kinsta blogg.

 

2 thoughts on “ElasticPress & WooCommerce: Deactivate Product Search Fuzziness

  1. This helped me a lot, thank you!
    Now I only have to find out how to put the search terms in an “AND” relation instead the default “OR” relation.

  2. Hi I can see that you have a well knowledge of Elasticpress, so I try my luck….
    I want to create a page with a search box that allows me to display a list of PDF documents corresponding to the keywords of my search. Currently my search is working and all the content of my PDFs is well indexed.
    I have a problem:
    – I don’t know how to use EP on a single search field (in my custom post type), and keep the classic WordPress search for other pages (blog, posts …..).
    I have tried this:
    add_filter( ‘ep_elasticpress_enabled’, ‘yourtheme_disable_ep_query’, 10, 2 );
    function yourtheme_disable_ep_query( $enabled, $query ) {
    if (! ($query->is_page( ‘ressources’ )) ) {
    return false;
    }
    return $enabled;
    }
    But nothing happend….
    Could you help me please ???? Thank you very much !!!!!

Leave a Reply

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