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:
320f408380b246cdb394fdf350f063b7|bc7c2c78e5b14959a7304e6e172159a8|cc9e97d12fe54d38aa60f2bb8ba5dc7d|bd5a6922f41746e89b93f9299e458221
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