apply_filters( 'relevanssi_fuzzy_query', string $query, string $term )
Filters the MySQL query used in partial word matching.
Parameters
$query
(string) The MySQL query, default "(relevanssi.term LIKE '#term#%' OR relevanssi.term_reverse LIKE CONCAT(REVERSE('#term#'), '%')) "
.
$term
(string) The search term.
More information
By default the partial matching in Relevanssi looks for matches in the beginning of the word (relevanssi.term LIKE '#term#%'
) or in the end of the word (relevanssi.term_reverse LIKE CONCAT(REVERSE('#term#'), '%')
. This is usually good, because it reduces the number of unrelevant matches. “Ban” will match “banana” or “urban”, but not “Albania”.
In some cases maximizing the recall is more important than precision, in which case it may make sense to make Relevanssi also match inside words. This can be done with this filter hook:
add_filter( 'relevanssi_fuzzy_query', 'rlv_match_inside_words' ); function rlv_match_inside_words( $query ) { return "(relevanssi.term LIKE '%#term#%') "; }
The #term#
is a code that will be later in the process replaced by the actual search term.