Query on sortby (replica index) on attributes that support multi-lingual data

Hello,
In our index there are like 4-5 fields which are localized. For eg: name, shortDescription, longDescription. Since there are only few fields, we decided to have only one index for this data. So based on the input data that we receive, we see the language code, and create fields like name_en, shortDescription_en, name_de, etc…So ideally these fields are all created during the pre-processing stage and then the json is pushed to Algolia.
We have a requirement of SORT by NAME A-Z, Z-A.

  1. So i wanted to know if its possible to create replica index when we receive the data first time. Say when we push the data to index, can we also create those many replica indices ? So in my case, if the data supports EN and ES, after/before pushing the data, can i create 4 replicas - 2 for EN i.e. name_en_asc and name_en_desc and 2 for ES i.e. name_es_asc and name_es_desc ?
  2. Or is it possible to do it at the query time ?

WHich of these is a better option here in terms of complexity, performance, flexibility (to support more languages), etc…

Also, will it be better to actually consider a separate index itself for each language so that the sorts become easier to manage ?

Please suggest.

Thanks.

Hi Tina,

You won’t be able to create new indices/change sort orders at query time – the Algolia model requires the indexing to happen ahead of time.

If you have the replicas pre-defined with the the various sort orders, the replicas are tied to your main index, so as you push new records they will automatically re-calculate the sort orders as they index the new records. You can also create replicas programmatically using the setSettings API (Create a replica index | Algolia) as you see new languages.

That said, I’m not sure you need replicas for this functionality. If you look at this guide ( Multilingual search | Algolia) the recommendation is to help users find records in the appropriate language by restricting the searchable attributes to only those that match that language at query time. Here’s the example:

// search only in the English records
index.search('wolf', {
  'restrictSearchableAttributes': [' name_en', 'shortDescription_en'] 
}).then(({ hits }) => {
  console.log(hits);
});

Thanks @chuck.meyer.
Yes, restrictedSearchableAttributes will work in case of search but i think the searchableAttributes will have to be defined (which will include all the fields) even before creating the index. The issue is that we may not know all the languages until we get the data load. (since the customer is not sure as of now of what all languages will be there. But we want to ensure that our index is ready to accomodate multiple languages)
Also, there is a sorting feature on Product name and since names are being localized, we will have productName_en, productName_fr, etc… and we will need to sort on these fields. Hence i wanted to know if we can add this sorting dynamically at runtime. (which means creating replicas before data load).

We sensed that this may be an issue and hence we are planning to use single index per language to reduce these complexities and have better control and a cleaner approach.

Thank you.

1 Like