Problem: Inconsistent Index Name
Closed this issue · 0 comments
Brief bug description
If we use a custom IAlgoliaIndexService
to customize the name of the index (for example, multiple indexes in the same Algolia account but selected based on the environment that the Xperience site is running in), we won't be able to query from the index on the client side using the following JavaScript:
<script type="text/javascript">
var client = algoliasearch('@algoliaOptions.ApplicationId', '@algoliaOptions.SearchKey');
var index = client.initIndex('@AlgoliaSiteSearchModel.IndexName');
</script>
Here, AlgoliaSiteSearchModel.IndexName
is not the necessarily the same index name that IAlgoliaIndexService
uses internally.
We need a way to get access to the modified index name used by IAlgoliaIndexService
to initialize an index and pass this to the client-side.
Repro steps
-
Create a custom
IAlgoliaIndexService
and modify how it initializes an index:public ISearchIndex InitializeIndex(string indexName) { return searchClient.InitIndex($"test-{indexName}"); } ```
-
Initialize a JavaScript based index using the
AlgoliaSiteSearchModel.IndexName
value:<script type="text/javascript"> var client = algoliasearch('@algoliaOptions.ApplicationId', '@algoliaOptions.SearchKey'); var index = client.initIndex('@AlgoliaSiteSearchModel.IndexName'); </script>
-
See the search client fail to query the non-existent index
Expected behavior
We can retrieve the 'customized' index name for client-side use.
Test environment
- n/a
Additional context
We might need to create another method on ISearchIndexService
to return the customized name since the Algolia SearchIndex
type does not expose the index's name that it is initialized with.
Screenshots
n/a