I understand how can work for text indexing. Will I be able to efficiently search for documents based on a given date range? Or will just use text matching to match the dates?

+6  A: 

Lucene.Net will just use text matching, so you'd need to format the dates correctly before adding to the index:

    public static string Serialize(DateTime dateTime)
        return dateTime.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);

    public static DateTime Deserialize(string str)
        return DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);

You can then, for example, perform a range based query to filter by date (e.g. 2006* to 2007* to include all dates in 2006 and 2007).

Stefan Schultze
I know little to nothing about lucene as im just trying to teach myself, but this answer threw me off for a while because the milliseconds are missing from the datetime, you want (well i did) "yyyyMMddHHmmssfff"
Andrew Bullock
Careful with running into problems going over maxClauseCount (default of 1024) as a RangeQuery expands under the covers to a BooleanQuery with all matching terms OR'd together. With dates (because they're indexed as text), the number of terms gets large quickly. See


I went in to trouble when i converted date in to yyyymmddHHmmssff. When i tried sorting the data, it gave me an exception that too big to convert..something. Hence i search and found then you need to have two columns. one in yyyymmdd and the other HHmmss, and then use Sort[] and give these two columns and then use. This will solve the issue.