Lucene: Indexing DateTime from Sitecore and querying date ranges

The title should be self explanatory. I need to index some sitecore items that represent some entities that are valid to the public between certain dates. The sitecore fields are date time fields looking like this.

Image

I needed a solution for indexing these values in a way that i can do range queries on them. I used the UnixTimeStamp for converting the DateTime field in a UnixTimeStamp field.

Decoding UnixTimeStamp to DateTime :

The fields would then be indexed as numbers and i could filter the results using a TermRangeQuery on the index like this:

I think this solution is quite elegant and easy to use.

Avatar photo

Alin Parjolea

System Developer at Pentia. I have been involved in small and large scale projects using Sitecore and .Net for the last 4 years. I am Sitecore certified developer since 2009. I have a Master degree in Computer Science from University of Southern Denmark. More detailed info about me can be found on my Facebook and LinkedIn pages.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website