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.
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);
}