Sandy
03/05/2025, 11:09 AMcsharp
[Const.PropertyChannel] = string.Join(",", property.GetChannels().Select(x => ((int)x))),
this always shows as correct but for some reason anything that has more than on channel e.g. 0,1 is missing the channel field in the index.
This is hard to fix as I’m not sure what isn’t right about it.
The index composer is:
csharp
builder.Services.AddExamineLuceneIndex<PropertyIndex, ConfigurationEnabledDirectoryFactory>("PropertyIndex");
builder.Services.ConfigureOptions<ConfigurePropertyIndexOptions>();
builder.Services.AddSingleton<PropertyIndexValueSetBuilder>();
builder.Services.AddSingleton<IIndexPopulator, PropertyIndexPopulator>();
builder.AddNotificationHandler<ContentCacheRefresherNotification, PropertyIndexingNotificationHandler>();
Which should be the right order as the index is working otherwise. I’m just a bit stuck now.
Thanks in advance for your help! Just let me know if more info is needed and I can provide it.Luuk Peters (Proud Nerds)
03/05/2025, 11:11 AMSandy
03/05/2025, 11:13 AMSandy
03/05/2025, 3:05 PMSandy
03/07/2025, 9:27 AMSandy
03/07/2025, 9:28 AMSandy
03/07/2025, 9:29 AMSandy
03/07/2025, 9:34 AMcsharp
public class PropertyIndexPopulator : IndexPopulator
{
private readonly IContentService _contentService;
private readonly PropertyIndexValueSetBuilder _propertyIndexValueSetBuilder;
public PropertyIndexPopulator(IContentService contentService, PropertyIndexValueSetBuilder propertyIndexValueSetBuilder)
{
_contentService = contentService;
_propertyIndexValueSetBuilder = propertyIndexValueSetBuilder;
RegisterIndex("PropertyIndex");
}
protected override void PopulateIndexes(IReadOnlyList<IIndex> indexes)
{
foreach (IIndex index in indexes)
{
IContent[] roots = _contentService.GetRootContent().ToArray();
index.IndexItems(_propertyIndexValueSetBuilder.GetValueSets(roots));
foreach (IContent root in roots)
{
const int pageSize = 100;
var pageIndex = 0;
IContent[] descendants;
do
{
descendants = _contentService.GetPagedDescendants(root.Id, pageIndex, pageSize, out _).ToArray();
IEnumerable<ValueSet> valueSets = _propertyIndexValueSetBuilder.GetValueSets(descendants);
index.IndexItems(valueSets);
pageIndex++;
}
while (descendants.Length == pageSize);
}
}
}
}
I used the umbraco docs to build it all and I don't know the nuances. I also need to make other changes to the index but this one is the most important to fix as it denotes where they appear in our listingsLuuk Peters (Proud Nerds)
03/07/2025, 9:49 AMSandy
03/07/2025, 9:53 AMSandy
03/07/2025, 9:56 AMcsharp
public IEnumerable<ValueSet> GetValueSets(params IContent[] content)
{
foreach (var propertyPage in content.Where(CanAddToIndex))
{
using var _ = _umbracoContextFactory.EnsureUmbracoContext();
var property = _?.UmbracoContext?.Content?.GetById((int)propertyPage.Id)?.Cast<PropertyPage>();
if (property != null)
{
var indexValues = PopulateValues(property);
yield return new ValueSet(property.Id.ToString(), IndexTypes.Content, property.ContentType.Alias, indexValues);
}
}
}
private bool CanAddToIndex(IContent content) => content.ContentType.Alias == "propertyPage";
private Dictionary<string, object> PopulateValues(PropertyPage property)
{
using var _ = _umbracoContextFactory.EnsureUmbracoContext();
var values = new Dictionary<string, object>()
{
// Populate standard fields
[UmbracoExamineFieldNames.NodeNameFieldName] = property.Name!,
["name"] = property.Name!,
["id"] = property.Id,
[Const.PropertyChannel] = string.Join(",", property.GetChannels().Select(x => ((int)x))),
//code skipped here (continues adding values in this way)
return values;
}
Mike Chambers
03/07/2025, 10:02 AMSandy
03/07/2025, 10:05 AMMike Chambers
03/07/2025, 10:08 AMSandy
03/07/2025, 10:09 AMMike Chambers
03/07/2025, 10:09 AMSandy
03/07/2025, 10:27 AMSandy
03/07/2025, 10:27 AMSandy
03/07/2025, 10:28 AMLuuk Peters (Proud Nerds)
03/07/2025, 10:29 AMcsharp
options.FieldDefinitions = new FieldDefinitionCollection(
new FieldDefinition(IndexFieldNames.Key, FieldDefinitionTypes.FullText),
new FieldDefinition(IndexFieldNames.Id, FieldDefinitionTypes.Integer),
new FieldDefinition(IndexFieldNames.Name, FieldDefinitionTypes.FullTextSortable),
...
}
Do you also have this? And is the type correct?Sandy
03/07/2025, 10:34 AMcsharp
options.FieldDefinitions = new(
new FieldDefinition(Const.PropertyChannel, FieldDefinitionTypes.Integer),
new FieldDefinition(Const.SellingPrice, FieldDefinitionTypes.Integer),
new FieldDefinition(Const.Rent, FieldDefinitionTypes.Integer),
new FieldDefinition(Const.Lat, FieldDefinitionTypes.Double),
new FieldDefinition(Const.Long, FieldDefinitionTypes.Double),
new FieldDefinition(Const.InternalAreaVal, FieldDefinitionTypes.Double),
new FieldDefinition(Const.ExternalAreaVal, FieldDefinitionTypes.Double),
new FieldDefinition(Const.ToLet, FieldDefinitionTypes.Integer),
new FieldDefinition(Const.ForSale, FieldDefinitionTypes.Integer),
new FieldDefinition(Const.SoldSTC, FieldDefinitionTypes.Integer),
new FieldDefinition(Const.InstructionDate, FieldDefinitionTypes.Long),
new FieldDefinition(Const.SellingInstructionDate, FieldDefinitionTypes.Long),
new FieldDefinition(Const.LettingInstructionDate, FieldDefinitionTypes.Long),
new FieldDefinition(Const.CreatedDate, FieldDefinitionTypes.Long),
new FieldDefinition(Const.OfficeId, FieldDefinitionTypes.Integer)
);
I've tried this as fulltext and fulltextsortable but neither seems to have any affect on the channel indexingSandy
03/07/2025, 10:34 AMSandy
03/07/2025, 10:34 AMSandy
03/07/2025, 10:35 AMSandy
03/07/2025, 10:35 AMLuuk Peters (Proud Nerds)
03/07/2025, 10:36 AMSandy
03/07/2025, 10:36 AMSandy
03/07/2025, 10:37 AMLuuk Peters (Proud Nerds)
03/07/2025, 10:38 AMSandy
03/07/2025, 10:38 AMLuuk Peters (Proud Nerds)
03/07/2025, 10:39 AMSandy
03/07/2025, 10:43 AM