Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DateOnly in range query #314

Closed
bjarnef opened this issue Nov 21, 2022 · 3 comments · Fixed by #315
Closed

Support DateOnly in range query #314

bjarnef opened this issue Nov 21, 2022 · 3 comments · Fixed by #315

Comments

@bjarnef
Copy link
Contributor

bjarnef commented Nov 21, 2022

Currently it seems DateOnly doesn't work in range query, while DateTime does.

public void Configure(string name, LuceneDirectoryIndexOptions options)
{
    switch (name)
    {
        case Umbraco.Cms.Core.Constants.UmbracoIndexes.ExternalIndexName:
            options.FieldDefinitions.TryAdd(new FieldDefinition(UmbracoExamineFieldNames.NodeNameFieldName, FieldDefinitionTypes.FullTextSortable));
            options.FieldDefinitions.TryAdd(new FieldDefinition(Constants.Examine.Course.FieldNames.CategoriesCount, FieldDefinitionTypes.Integer));
            options.FieldDefinitions.TryAdd(new FieldDefinition(Constants.Examine.Course.FieldNames.ExpirationDate, FieldDefinitionTypes.DateTime));
            break;
    }
}

and

if (expiryDate.HasValue)
{
      query.And().RangeQuery<DateOnly>(new[] { SearchField.Course.ExpirationDate },
          expiryDate.Value,
          DateOnly.MaxValue,
          minInclusive: true);
}

image

However if I use DateTime instead of DateOnly it works.

if (expiryDate.HasValue)
{
      query.And().RangeQuery<DateTime>(new[] { SearchField.Course.ExpirationDate },
          expiryDate.Value,
          DateTime.MaxValue,
          minInclusive: true);
}

I guess it should have a DateOnlyType.cs here: https://github.com/Shazwazza/Examine/tree/07d0889d6d0a9ea06b9bae34a068dcb959e3322f/src/Examine.Lucene/Indexing

@bjarnef
Copy link
Contributor Author

bjarnef commented Nov 21, 2022

Should we also support TimeOnly in .NET6+?
https://medium.com/@niteshsinghal85/converting-dateonly-and-timeonly-to-datetime-and-vice-versa-in-net-6-72db56853857

Could be useful if implementing a custom property editor using a date picker (only date) or a time picker.

@nikcio
Copy link
Contributor

nikcio commented Nov 21, 2022

Hi @bjarnef I've looked a bit into this and this can be done without creating a new indexing method and by modifying RangeQueryInternal instead see #315

I don't know if TimeOnly makes much sense to solve in this way because then which day should then be used so this might require new indexing to work properly.

@bjarnef
Copy link
Contributor Author

bjarnef commented Nov 21, 2022

@nikcio okay great ;)
Not sure about TimeOnly but I guess is could use any date, like date of DateTime.Min (which is default date of DateTime).

Or it could use the ticks as int or long value. I think it was the old way to handle sorting of DateTime in Examine, but now it works using DateTime OOTB. I only needed to define custom datetime properties as datetime as it is fulltext by default.

Shazwazza added a commit that referenced this issue Nov 29, 2022
Add `DateOnly` support to `RangeQuery` (#314 & #307)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants