Hyphens in SKU's using Autocomplete

I have users entering search terms with hyphens that come up empty because the SKU does not contain a hyphen. What configurations changes can I make to ensure the SKU’s results show regardless of the hyphen?

As an example, The attribute indexed in Algolia is 922684

If I search for 922-684 it will return zero results.
If I search for 922- it will return proper results.

What can I do to ignore the hyphen as a break character in the SKU attribute? We have thousands of SKU’s and entering them as synonyms is not a great approach for us.

Thanks!

Ping - Can Anyone give me some feedback?

Hello @mmcbrien,

unfortunately engine is not able to handle split / concat with hyphens on attributes composed only with numbers (even when they’re indexed as strings).
The possible workaround would be to index both format in sku attribute.

In Magento you can do it with leveraging custom events to write your code to enrich data. Would that work for you?

@jan.petr So - If I am understanding you correctly your suggesting I use a custom event to remove the hyphen and index it as a separate SKU attribute?

If I take this route, would I be using the algolia_after_create_product_object event? ( then run a regex or similar to remove the hyphen, and add a new attribute name prior to indexing)

Do you happen to have an example code of this in use?

Thank you for taking the time to respond, it’s much appreciated.

Actually I meant to add a new SKU with hyphen. I though that the one indexed is 922684 and you want it to be retrieved even for query 922-684.

So to achieve that you can use event algolia_after_create_product_object where you can modify $record. The $record has attribute sku and it looks like this:

$record['sku'] = 922684;

What you want to do in the event is to change SKU to array and add the value with hyphen. So it might look like this:

$record = [922684, '922-684'];

Then the record will be found for both queries: 922684 and 922-684.

1 Like