0

Using Sitecore 9.3 and Azure search. We have a single Sitecore CM instance setup with two content trees:

  • /sitecore/content/siteOne
  • /sitecore/content/siteTwo

We have separate CD sites for each of the above sites. When a user searches in siteOne, we only want results from siteOne's content tree, and likewise for siteTwo.

Is this even possible? I've searched StackExchange and the Sitecore Community for examples - any examples of how to set this up, and I am not finding anything.

0

1 Answer 1

2

This is not an Azure Search problem. You can use the ContentSearchAPI to filter your results based on the path of the items returned.

using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext())  
{
  // Create an initial predicate - use .True<T> since we'll be AND'ing this clause together with the search query
  var filterPredicate = PredicateBuilder.True<SearchResultItem>();
    
  // Filter by site
  filterPredicate = filterPredicate.And(x => x.Path.Contains("/sitecore/content/yoursite/home/path"));
  
  // Add your search query to the predicate
  fitlerPredicate = filterPredicate.Where(x => ......);
  
  // Fetch results from the search index using the predicate
  var results = context.GetQueryable<SearchItemResult().Filter(filterPredicate); 
}

This will limit the search results to a single sites content. Of course you can get more finely grained if you need to only search within a specific section of content.

2
  • Other option can be, creation of the Site specific custom SOLR index sitecorediaries.org/2020/05/24/…
    – Amit Kumar
    Commented Jan 24, 2023 at 23:10
  • @AmitKumar Current implementation is using Azure search - we may switch to using Solr, but not for now.
    – T H
    Commented Jan 25, 2023 at 19:35

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.