When searching for dimensions and measurements, problems can arise with the formatting of the record data as users will search with various syntaxes.
For example, users can search for "timber 2.8 x 14.5 cm" (spaces with metrics) or "timber 2.8x14.5" (no spaces and no metrics) or any combination of including spaces around the "x" or including metrics. In these situations, preparing your index in the correct manner is crucial for Algolia to be able to retrieve the most relevant records.
There are two approaches that can be taken to solve this issue, the first would create many synonyms between various ways of writing the dimensions and the second would be to index all different ways of writing the dimensions. Unfortunately, regardless of which option you choose, all the expected matches will need to be listed out.
Creating synonyms between all options:
You can add multi-way synonyms for these and other similar equivalences "2.8x14.5" <> "2.8 x 14.5" <> "2.8 x 14.5cm" <> "2.8 x 14.5 cm" etc. Please note that synonyms don't produce exactly equivalent results.
To learn more about synonyms please see this following article: https://www.algolia.com/doc/guides/managing-results/optimize-search-results/adding-synonyms
Typically, this issue is not confined to a single product and dimension and as such it is recommended to import them from a CSV file or using the API to programmatically create the synonyms.
Indexing all dimension options:
You can create a "dimension" attribute that would contain an array of all the variations of the dimensions. This would look like:
"dimension": ["2.8x14.5, "2.8 x 14.5", "2.8 x 14.5cm", "2.8 x 14.5 cm"]
Once this has been created, please ensure that this attribute is searchable so that any query will be able to match on the values.
Further complications arise when trying to distinguish between 5mm and 10.5mm items, where searching for "5mm" would also return the results of 10.5mm. This is due to the "." being treated as a separator and not a searchable character.
A work around for this issue is to initially follow option 2 above (Indexing all dimension options) and then to add this attribute to your attributes for faceting list.
Then, create a rule where on the condition that the query includes the "dimensions" facet value, it will filter by that facet.
- https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/
Please see the syntax for this rule below:
This rule will now filter all queries that include a dimension in them by the "dimensions" facet that matches the dimension in the query.
It is worth bearing in mind that this will always trigger on queries with a facetted dimension in them and will only work in a situation where there is one dimension present in the query. if you search for "5mm x 10.5mm timber" for example while having both "5mm" and "10.5mm" as facetted dimensions, it would not know which dimension to filter on.