2

When making Content Search API calls, Sitecore resolves the index based on certain logic which is very well explained here.

In SXA, we do have an option to configure the indexes on the site item, like below.

enter image description here

In Content Search API, is it possible to resolve to these indexes?

0

1 Answer 1

3

In SXA, we have custom service called IndexResolver which we are using to resolve proper index (including site indexes if such are defined). It has the following priorities while resolving index:

  1. It will first, check if there are any language-specific indexes defined in the site, e.g.: master/en
  2. Then, it will check if there are any database indexes defined in the site, e.g.: web/*
  3. If there are no site-related indexes the logic will try to get default SXA index sitecore_sxa_master_index or sitecore_sxa_web_index
  4. If default SXA indexes won't be found, it will fallback to Sitecore logic and call ContentSearchManager.GetIndex(rootItem)

You can inject the IndexResolver using standard constructor injection or by using ServiceLocator.ServiceProvider.GetService<IIndexResolver>() and use it like this:

ISearchIndex searchIndex = IndexResolver.ResolveIndex(contextItem);
IProviderSearchContext search = searchIndex.CreateSearchContext();
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.