Hi
I'm right now using the standard externalIndex and it works pretty aye okay content-wise. BUT, I've come to a point where I want one of the fields to be indexed differently.
The field in question contains node id's whereas I want it to contain node names so I can easily search in it.
I'm having problems finding resources/documentation/guides how I can modify the field in externalIndex.
Would it instead be better to create a new content index where I seem to be able to adjust the fields more easily? Or any suggestions how to modify the existing index?
We always recommend that you use the existing built in ExternalIndex.
You should then query based on the NodeTypeAlias instead of creating a
new separate index based on that particular node type. However, should
the need arise, the example below will show you how to do it. Take a
look at our Examine Quick Start to see some examples of how to search
the ExternalIndex.
For example having a property with alias categories using a picker datatype (Content Picker, MNTP):
if (e.ValueSet.Values.ContainsKey("categories"))
{
// Prepare a new collection for category names
var categoryNames = new List<string>();
// Parse the comma separated list of category UDIs
var categoryIds = e.ValueSet.GetValue("categories").ToString().Split(',')
.Select(x => UdiParser.TryParse<GuidUdi>(x, out var id) ? id : null)
.Where(x => x != null)
.ToList();
// Fetch the category nodes and extract the category name, adding it to the names collection
using (var ctx = _umbracoContextFactory.EnsureUmbracoContext())
{
foreach (var categoryId in categoryIds)
{
var category = ctx.UmbracoContext.Content.GetById(categoryId);
if (category != null)
{
categoryNames.Add(category.Name);
}
}
}
// If we have some names, add these to the lucene index in a searchable way
if (categoryNames.Count > 0)
{
values.Add("categoryNames", new[] { string.Join(" ", categoryNames) });
}
}
New index or modify existing?
Hi I'm right now using the standard externalIndex and it works pretty aye okay content-wise. BUT, I've come to a point where I want one of the fields to be indexed differently.
The field in question contains node id's whereas I want it to contain node names so I can easily search in it.
I'm having problems finding resources/documentation/guides how I can modify the field in externalIndex.
Would it instead be better to create a new content index where I seem to be able to adjust the fields more easily? Or any suggestions how to modify the existing index?
(Umbraco 11)
https://docs.umbraco.com/umbraco-cms/reference/searching/examine/indexing
Here is a typical example from Vendr demostore where one wants to index node data from picked nodes. https://github.com/vendrhub/vendr-demo-store/blob/v3/dev/src/Vendr.DemoStore/Events/TransformExamineValues.cs#L44-L73
For example having a property with alias
categories
using a picker datatype (Content Picker, MNTP):Thanks both of you. This worked perfectly!
is working on a reply...