FacetWP Autocomplete facet – return only results matching the exact value entered

<?php

// Without this snippet, the Autocomplete facet's SQL is using " LIKE '%value%'", which returns partial matches.
// With the snippet, it will use " = 'value'", resulting in only matches in the filtered post results that are exactly the entered value.
// For results starting with the value, see: 
// https://gist.facetwp.com/gist/facetwp-autocomplete-facet-return-only-results-starting-with-the-value-entered/

add_filter( 'facetwp_wpdb_sql', function( $sql, $facet ) {

  if ( 'my_autocomplete' == $facet['name'] ) { // Replace 'my_autocomplete' with the name of your Autocomplete facet
    global $wpdb;
    $sql = $wpdb->remove_placeholder_escape( $sql );
    $sql = str_replace(" LIKE '", " = '", $sql);
    $sql = str_replace("%", "", $sql);
  }

  return $sql;
}, 10, 2 );