Using date range in Lucene.net

I understand how Lucene.net can work to index text. Will I be able to efficiently search for documents based on a given date range? Or is Lucene.net just using text matching according to dates?

+3
source share
2 answers

Lucene.Net will just use text matching, so you 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);
    }

Then you can, for example, run a range-based query to filter by date (for example, from 2006 * to 2007 * to include all dates in 2006 and 2007).

+6
source

, yyyymmddHHmmssff. , , ... -. , , . yyyymmdd, HHmmss, Sort[] , . .

+1

Source: https://habr.com/ru/post/1699677/


All Articles