0

I am using Sitecore 10.2 in local on containers. I have created a custom indexer, and it is reflecting both in Solr and Sitecore showconfig. How do I bring sxa search results from the custom indexers? I am using all the OOTB search result component.

Thanks on advance

0

2 Answers 2

1

Update:

If you are using OOB SXA Search then SXA Search resolves the index name using 'Sitecore.XA.Foundation.Search.Services.IndexResolver.ResolveIndex' You can check the code, but it takes the index name based on context database from the fields I shared below. If you like you can also override that method to simply return ContentSearchManager.GetIndex({Your index name}). Assuming your index exists in the config

Original:

Go to /sitecore/content/{Tenant}/{Site}/settings/Site Grouping/{Your site name} and add indexes for web and master DBs as follow:

enter image description here

4
  • I have tried this, but this does not fulfill my requirement. I am using a custom index a, and crawler. the page (and its subitem) for which I have added the crawler, a search component is added on that page, and I want search results to fetch from custom index.
    – user13291
    Jun 30, 2023 at 10:32
  • If you are using OOB SXA Search then SXA Search resolves the index name using 'Sitecore.XA.Foundation.Search.Services.IndexResolver.ResolveIndex' You can check the code, but it takes the index name based on context database from the fields I shared above. If you like you can also override that method to simply return ContentSearchManager.GetIndex({Your index name}). Assuming your index exists in the config. Jun 30, 2023 at 11:10
  • Thanks!. That really, helped. I would suggest adding this detail to your answer.
    – user13291
    Jun 30, 2023 at 16:17
  • Glad it helped. Just added it to the answer. Thanks and have a great day. Jun 30, 2023 at 17:36
0

If you wish to have index per site then SXA has that provision which mentioned in other answers. Otherwise if you want to incorporate multiple indexes, I could not find any direct way to pass your custom index in scope. Since you are using OOTB components, we can try something that keeps native feature intact. I have not done this myself but this is what I would try.

  • Create a custom attribute in Sitecore which can be passed in scope.

enter image description here

Then you will need to override GetQuery method in SearchService to utilize this index (if set in scope). This way we can use separate index for for every scope. Do make sure to to fall back to default logic, if index is not set from scope.

//Sitecore namespace - Sitecore.XA.Foundation.Search.Services

public virtual IQueryable<ContentPage> GetQuery(
  SearchQueryModel searchQueryModel,
  out string indexName)
{
  Item contextItem = this.GetContextItem(searchQueryModel.ItemID);
  ISearchIndex searchIndex = this.IndexResolver.ResolveIndex(contextItem);
  IList<Item> list = (IList<Item>) searchQueryModel.ScopesIDs.Select<ID, Item>(new Func<ID, Item>(this.Context.Database.GetItem)).ToList<Item>();
  // You can insert your index here
  indexName = searchIndex.Name;
  IEnumerable<SearchStringModel> models = list.Select<Item, string>((Func<Item, string>) (i => i["ScopeQuery"])).SelectMany<string, SearchStringModel>(new Func<string, IEnumerable<SearchStringModel>>(SearchStringModel.ParseDatasourceString));
  IEnumerable<SearchStringModel> searchStringModel = this.ResolveSearchQueryTokens(contextItem, models);
  IQueryable<ContentPage> query = LinqHelper.CreateQuery<ContentPage>(searchIndex.CreateSearchContext(), searchStringModel);
  string str = this.NormalizeSearchPhrase(searchQueryModel.Query);
  IQueryable<ContentPage> queryable = query.Where<ContentPage>(this.IsGeolocationRequest ? this.GeolocationPredicate(searchQueryModel.Site) : this.PageOrMediaPredicate(searchQueryModel.Site)).Where<ContentPage>(this.ContentPredicate(str)).Where<ContentPage>(this.LanguagePredicate(searchQueryModel.Languages)).Where<ContentPage>(this.LatestVersionPredicate()).ApplyFacetFilters(this.Context.Request.QueryString, searchQueryModel.Coordinates, searchQueryModel.Site);
   return this.BoostingService.BoostQuery(list, str, contextItem, queryable);
}

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