Monday, May 9, 2016

Sitecore search and the treelist field

When Lucene indexes a treelist field in Sitecore, the IDs of the selected items are stored in the search index, separated by the pipe ("|") character. An example would be:
You might also notice that the IDs are not stored in the expected GUID format and instead are in a normalized form. To convert a standard Guid ID to this form:
var myNormalizedGuid = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(MyGuid);
This means that the treelist field can be queried by searching if the field contains a normalized GUID:
var searchResults = searchContext.GetQueryable<MyResultItem>().Where(x => x.Categories.Contains(myNormalizedGuid));

No comments:

Post a Comment