Last active
August 3, 2016 16:05
-
-
Save soen/d3d3a203024746927f1fb8088a5ea545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
var filterPredicate = PredicateBuilder.True<SearchResultItem>(); | |
// Ensure correct parent | |
filterPredicate = filterPredicate.And(x => x.Parent == ID.Parse("TheParentId")); | |
// Ensure correct path | |
filterPredicate = filterPredicate.And(x => x.Path.Contains("/Path/To/SearchResults")); | |
// Ensure correct naming conventions - use .False<T> since we'll be OR'ing this clause together | |
var namingPredicate = PredicateBuilder.False<SearchResultItem>(); | |
namingPredicate = namingPredicate.Or(x => x.Name.StartsWith("A") | |
.Or(x => x.Name.StartsWith("B") | |
.Or(x => x.Name.StartsWith("C"); | |
// Append the naming predicate to the overall filter predicate | |
filterPredicate = filterPredicate.And(namingPredicate); | |
// Fetch results from the search index using the predicate | |
var results = context.GetQueryable<SearchItemResult().Filter(filterPredicate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment