Hi, Is there any way in Umbrac v9 to exclude certain content values from the examine index? In this instance I have a multi-node treepicker used to highlight related content which I want to exclude from search indexing and showing up in the search results. Currently I have overridden the 'PerformingIndexValues' event to do this, but I can only see an option to add or combing values, instead of removing them from the Index (see code below).
private void IndexProviderTransformingIndexValues(object sender, IndexingItemEventArgs args)
{
try
{
if (int.TryParse(args.ValueSet.Id, out var pageId))
{
if (args.ValueSet.ItemType == "newsArticle") //Set news article custom index fields
{
using (UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext())
{
var contentNode = umbracoContextReference.UmbracoContext.Content.GetById(pageId);
if (contentNode != null)
args = SetSearchableValues(args, contentNode);
}
}
}
}
catch (Exception e)
{
_logger.LogError(e, "IndexProviderTransformingIndexValues: Exception: {0} | Message: {1} | Stack Trace: {2}", e.InnerException != null ? e.InnerException.ToString() : "", e.Message != null ? e.Message.ToString() : "", e.StackTrace);
}
}
private IndexingItemEventArgs SetSearchableValues(IndexingItemEventArgs args, IPublishedContent contentNode)
{
try
{
var combinedFields = new StringBuilder();
//Loop through all fields and combine into single string of searchable content
foreach (var fieldValues in args.ValueSet.Values)
{
foreach (var value in fieldValues.Value)
{
if (value != null)
combinedFields.AppendLine(value.ToString());
}
}
//Index custom field values
args.ValueSet.Add("searchHomepageKey", contentNode.AncestorOrSelf("homePage").Key.ToString());
args.ValueSet.Add("searchParentKey", contentNode.Parent.Key.ToString());
args.ValueSet.Set("searchCurrentKey", contentNode.Key.ToString());
args.ValueSet.Add("searchableKeywords", combinedFields.ToString().ToLower());
args.ValueSet.Set("sortableDate", contentNode.CreateDate.ToString("yyyyMMddHHmmss"));
}
catch (Exception e)
{
_logger.LogError(e, "SetSearchableValues: Exception: {0} | Message: {1} | Stack Trace: {2}", e.InnerException != null ? e.InnerException.ToString() : "", e.Message != null ? e.Message.ToString() : "", e.StackTrace);
}
return args;
}
Excluding node value from Examine index
Hi, Is there any way in Umbrac v9 to exclude certain content values from the examine index? In this instance I have a multi-node treepicker used to highlight related content which I want to exclude from search indexing and showing up in the search results. Currently I have overridden the 'PerformingIndexValues' event to do this, but I can only see an option to add or combing values, instead of removing them from the Index (see code below).
Any help much appreciated.
is working on a reply...