For starters, I would remove all your custom functions. Some of them don’t do anything, and some of them do unexpected things that are not necessary. Relevanssi doesn’t consider numbers as stopwords, unless you explicitly set it up like that. Relevanssi, however, ignores one-letter words, which makes Relevanssi ignore single numbers.
The main problem here stems from the fact that Relevanssi by default does not match inside words. So if you keep the dashes and the product code is indexed as “DS-KH9310-WTE1”, the “9310” is inside the word and Relevanssi can’t match it. Relevanssi matches beginning and end, so “DS-KH” and “10-WTE1” both work, as you can see on your site.
There are a couple of approaches here. The easiest solution is to enable inside-word matching with this:
add_filter( 'relevanssi_fuzzy_query', 'rlv_partial_inside_words' );
function rlv_partial_inside_words( $query ) {
return "(relevanssi.term LIKE '%#term#%')";
}With this snippet, “9310” will find the product. This will, however, increase the amount of garbage results. See if the balance is fine. If it’s not, then you can remove this and instead add a filter in the indexing step to index the parts of the product codes you want searchable. In this case, you could index the product code as “DS-KH9310-WTE1 KH9310”, which would make it possible to find it with “9310”.
Thank you! That’s perfect!
However, there’s one thing I’m unclear about: when I search using the number “9310,” this product also appears in the search results: Product Link, even though it doesn’t explicitly contain this number.
How to improve?
With the Relevanssi debugging enabled, I could tell it exactly, but I’m guessing you’re indexing all visible custom fields and the product has the number in one of the custom fields.
