RangeQuery on DateField fails with exception saying it's a FullText field
I have a Umbraco 13 project where we built a custom index for activities that we fetch from a remote API.
I'm trying to do a RangeQuery on one of the fields that contains a date to see if the activity falls within the bounds of 2 different dates.
This is how we set the FieldDefinitions.
var definitions = new FieldDefinitionCollection(
new FieldDefinition(nameof(IActivityIndexItem.FromDate), FieldDefinitionTypes.FullText),
new FieldDefinition(nameof(IActivityIndexItem.ToDate), FieldDefinitionTypes.FullText),
new FieldDefinition(nameof(IActivityIndexItem.FromDateAsDateTime), FieldDefinitionTypes.DateTime));
foreach(var definition in definitions){
options.FieldDefinitions.AddOrUpdate(definition);}
And if i go in the backoffice and search the index i can see that the date is stored correctly in the index.
(FromDate is the same value but stored as FullText)
But when i try to do a RangeQuery on the field called "FromDateAsDateTime" like this:
DateTime dateFromDate;
if (DateTime.TryParseExact(dateFrom, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out dateFromDate))
{
searchQuery = searchQuery
.And()
.RangeQuery<DateTime>([CustomIndexKeys.FromDateAsDateTime], dateFromDate, DateTime.MaxValue);
}
I get the following error:
Message = "Could not perform a range query on the field FromDateAsDateTime, it's value type is Examine.Lucene.Indexing.FullTextType"
I've been pulling my hair about this all week.
Can anyone help me understand why this happens?
Thanks for your suggestion, unfortunately i have already tried that and got the same error.
The good thing is that i think i might have found the issue.
We use a multisearcher to search in several indexes at the same time.
And it seems like when using the multisearcher all fields in the indexes are treated as FullTextFields for some reason. Not sure if it is a bug or if that is the intended behaviour.
If i get a searcher directly from my custom activity index, i can do a RangeQuery the way i want to. So i guess not using the multisearcher will have to be my solution for now :)
RangeQuery on DateField fails with exception saying it's a FullText field
I have a Umbraco 13 project where we built a custom index for activities that we fetch from a remote API. I'm trying to do a RangeQuery on one of the fields that contains a date to see if the activity falls within the bounds of 2 different dates.
This is how we set the FieldDefinitions.
And if i go in the backoffice and search the index i can see that the date is stored correctly in the index. (FromDate is the same value but stored as FullText)
But when i try to do a RangeQuery on the field called "FromDateAsDateTime" like this:
I get the following error: Message = "Could not perform a range query on the field FromDateAsDateTime, it's value type is Examine.Lucene.Indexing.FullTextType"
I've been pulling my hair about this all week. Can anyone help me understand why this happens?
I had issues trying to use dates so I changed my index to store ticks instead and then used that in the range query
Field definition
new("updated", FieldDefinitionTypes.Long),
populating index["updated"] = content.UpdateDate.Ticks,
Range query
Hello Huw!
Thanks for your suggestion, unfortunately i have already tried that and got the same error.
The good thing is that i think i might have found the issue. We use a multisearcher to search in several indexes at the same time. And it seems like when using the multisearcher all fields in the indexes are treated as FullTextFields for some reason. Not sure if it is a bug or if that is the intended behaviour.
If i get a searcher directly from my custom activity index, i can do a RangeQuery the way i want to. So i guess not using the multisearcher will have to be my solution for now :)
is working on a reply...