#Examine Search where date field is LessOrEqual to Now ?
1 messages · Page 1 of 1 (latest)
Looks like the package doesn't have anything for datetimes, so the standard Examine way of searching should be the go-to:
https://shazwazza.github.io/Examine/docs-v1-v2/searching.html?q=date#date-range
Cool, but how do I do that on a custom field ?
So let's say you have a doctype called "events" with a property called "startTime". Then something like this:
IBooleanOperation query = index
.Searcher.CreateQuery()
.NodeTypeAlias("events")
.And()
.RangeQuery<DateTime>(["startTime"], DateTime.MinValue, DateTime.Now);
That would query for all documents of the nodeType events and the startTime between DateTime.MinValue and DateTime.Now
I think it's almost there. Can it be that I have to make FieldDefinition for the custom field ?
Oh yea probably, you can specify its type like this:
public class ConfigureExternalIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
public void Configure(string? name, LuceneDirectoryIndexOptions options)
{
if (name is not Constants.UmbracoIndexes.ExternalIndexName)
return;
options.FieldDefinitions.AddOrUpdate(
new FieldDefinition("startTime", FieldDefinitionTypes.DateTime)
);
}
public void Configure(LuceneDirectoryIndexOptions options)
{
Configure(string.Empty, options);
}
}
And then within a composer add this:
builder.Services.AddTransient<IConfigureOptions<LuceneDirectoryIndexOptions>, ConfigureExternalIndexOptions>();
Hmmmm ... my frontend keeps saying Could not perform a range query on the field pageDate, it's value type is Examine.Lucene.Indexing.FullTextType.
It's like the composer is never picked up.
I've attached a screendump of the composer and the IndexOptions.
It's an Umbraco V13 if it makesany difference
Line 14 you set the type to fulltext 😉
Should be FieldDefinitionTypes.DateTime
Bingo, that was the culprit 🙂
How would you go about multiple languages in this scenario ?
As for now I've done like this in the IndexOptions:
public void Configure(string? name, LuceneDirectoryIndexOptions options)
{
if (name != Constants.UmbracoIndexes.ExternalIndexName) return;
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("pageDate_da", FieldDefinitionTypes.DateTime));
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("pageDate_en", FieldDefinitionTypes.DateTime));
}