Search only 3 last digits of a serial number

Is there a way to only match the 3 last digits of a 13 digit input search? Visitors are entering a serial number, but I only need to match the last 3 digits of it, but I do need them to enter the entire serial number.

Hello,

There is no way to do that out of the box. All the queries done with Algolia are doing a prefix match (ie. search for a match from the first letter).

The way I would do it is would be a mix of changing the record format and front-end hooks.

I would first add a last_three_digits field to my records that I would populate with the last three digits of the serial number. This should be done in a pre-processing phase, when I’m pushing my records to Algolia.

I would configure my index settings with attributesForFaceting: ['last_three_digits'] so filtering can be done on this field (more documentation here)

Then I would add a hook on my front-end to intercept the query before it is sent to Algolia. If I detect a serial number in the query (13 digits), I would keep only the last three search for that instead. I would then remove the keyword from the query and replace it with a filtering on the last_three_digits facet. The exact way to do this would depend on the Algolia front-end library you’re using (InstantSearch, React InstantSearch, etc).

Hope that helps,