tl;dr
we’re adding a homeId field to the external index as a FieldDefinitionType.Integer and getting a Could not perform a range query on the field homeId, it’s value type is Examine.Lucene.Indexing.FullTextType exception.
hey out there,
we can’t work out if we’ve discovered a bug or new undocumented way of working but this is the problem we’ve hit…
this is how we’ve been configuring index options since v9:
public class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
public void Configure(string? name, LuceneDirectoryIndexOptions options)
{
switch (name)
{
case UmbracoIndexes.ExternalIndexName:
options.FieldDefinitions.AddOrUpdate(new FieldDefinition(Constants.Examine.Fields.HomeId, FieldDefinitionTypes.Integer));
break;
}
}
public void Configure(LuceneDirectoryIndexOptions options) => Configure(string.Empty, options);
}
public class Composer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.ConfigureOptions<ConfigureIndexOptions>();
}
}
we set the home id by transforming the index values in a component.
moving this code to our v16 site, we get an exception when attempting to run a range query on the field:
query
.And()
.RangeQuery<int>(
fields: "homeId",
min: 1234,
max: 1234);
debugging the code gave nothing away, everything was being hit as it should be but the suspicion was that the field was somehow not being set as an integer…
then randomly we found this forum post:
which had the marked solution of:
I found the issue for some reason my ConfigureOptions is gettng called before Umbraco, which overrrides everything. So I have move it to a PostConfigure call and it is now working.
there was no mention of what PostConfigure was or how it works but after some experimentation we tried this in our composer:
public class Composer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.PostConfigure<LuceneDirectoryIndexOptions>(
UmbracoIndexes.ExternalIndexName,
options =>
{
options.FieldDefinitions.AddOrUpdate(new FieldDefinition(Constants.Examine.Fields.HomeId, FieldDefinitionTypes.Integer));
}
);
}
}
and hey presto, everything started working again as expected!
we’ve double checked the docs Custom indexing | Umbraco CMS and it does seem that the way we’ve always been doing things is correct…
one thing we did wonder is if we should be using the [ComposeAfter(typeof(AnotherComposer))] attribute on our composer to ensure it loads after the umbraco core ones - but the documentation doesn’t mention the core composers and/or the order they load in so it’s not possible to work out what one our composer should load after?!
…so is this a bug?! or a new way of doing things?!