Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Classes | Static Public Member Functions | List of all members
Lucene.Net.Documents.DateTools Class Reference

Provides support for converting dates to strings and vice-versa. The strings are structured so that lexicographic sorting orders them by date, which makes them suitable for use as field values and search terms. More...

Classes

class  Resolution
 Specifies the time granularity. More...
 

Static Public Member Functions

static System.String DateToString (System.DateTime date, Resolution resolution)
 Converts a Date to a string suitable for indexing.
 
static System.String TimeToString (long time, Resolution resolution)
 Converts a millisecond time to a string suitable for indexing.
 
static long StringToTime (System.String dateString)
 Converts a string produced by timeToString or DateToString back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT.
 
static System.DateTime StringToDate (System.String dateString)
 Converts a string produced by timeToString or DateToString back to a time, represented as a Date object.
 
static System.DateTime Round (System.DateTime date, Resolution resolution)
 Limit a date's resolution. For example, the date 2004-09-21 13:50:11 will be changed to 2004-09-01 00:00:00 when using Resolution.MONTH.
 
static long Round (long time, Resolution resolution)
 Limit a date's resolution. For example, the date 1095767411000 (which represents 2004-09-21 13:50:11) will be changed to 1093989600000 (2004-09-01 00:00:00) when using Resolution.MONTH.
 

Detailed Description

Provides support for converting dates to strings and vice-versa. The strings are structured so that lexicographic sorting orders them by date, which makes them suitable for use as field values and search terms.

This class also helps you to limit the resolution of your dates. Do not save dates with a finer resolution than you really need, as then RangeQuery and PrefixQuery will require more memory and become slower.

Compared to DateField the strings generated by the methods in this class take slightly more space, unless your selected resolution is set to Resolution.DAY or lower.

Another approach is NumericUtils, which provides a sortable binary representation (prefix encoded) of numeric values, which date/time are. For indexing a DateTime, convert it to unix timestamp as long and index this as a numeric value with NumericField and use NumericRangeQuery{T} to query it.

Definition at line 47 of file DateTools.cs.

Member Function Documentation

static System.String Lucene.Net.Documents.DateTools.DateToString ( System.DateTime  date,
Resolution  resolution 
)
static

Converts a Date to a string suitable for indexing.

Parameters
datethe date to be converted
resolutionthe desired resolution, see Round(DateTime, DateTools.Resolution)
Returns
a string in format yyyyMMddHHmmssSSS or shorter, depending on resolution; using GMT as timezone

Definition at line 76 of file DateTools.cs.

static System.DateTime Lucene.Net.Documents.DateTools.Round ( System.DateTime  date,
Resolution  resolution 
)
static

Limit a date's resolution. For example, the date 2004-09-21 13:50:11 will be changed to 2004-09-01 00:00:00 when using Resolution.MONTH.

Parameters
date
resolutionThe desired resolution of the date to be returned
Returns
the date with all values more precise than resolution set to 0 or 1

Definition at line 233 of file DateTools.cs.

static long Lucene.Net.Documents.DateTools.Round ( long  time,
Resolution  resolution 
)
static

Limit a date's resolution. For example, the date 1095767411000 (which represents 2004-09-21 13:50:11) will be changed to 1093989600000 (2004-09-01 00:00:00) when using Resolution.MONTH.

Parameters
timeThe time in milliseconds (not ticks).
resolutionThe desired resolution of the date to be returned
Returns
the date with all values more precise than resolution set to 0 or 1, expressed as milliseconds since January 1, 1970, 00:00:00 GMT

Definition at line 250 of file DateTools.cs.

static System.DateTime Lucene.Net.Documents.DateTools.StringToDate ( System.String  dateString)
static

Converts a string produced by timeToString or DateToString back to a time, represented as a Date object.

Parameters
dateStringthe date string to be converted
Returns
the parsed time as a Date object

<throws> ParseException if dateString is not in the </throws>

expected format

Definition at line 157 of file DateTools.cs.

static long Lucene.Net.Documents.DateTools.StringToTime ( System.String  dateString)
static

Converts a string produced by timeToString or DateToString back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT.

Parameters
dateStringthe date string to be converted
Returns
the number of milliseconds since January 1, 1970, 00:00:00 GMT

<throws> ParseException if dateString is not in the </throws>

expected format

Definition at line 140 of file DateTools.cs.

static System.String Lucene.Net.Documents.DateTools.TimeToString ( long  time,
Resolution  resolution 
)
static

Converts a millisecond time to a string suitable for indexing.

Parameters
timethe date expressed as milliseconds since January 1, 1970, 00:00:00 GMT
resolutionthe desired resolution, see Round(long, DateTools.Resolution)
Returns
a string in format yyyyMMddHHmmssSSS or shorter, depending on resolution; using GMT as timezone

Definition at line 92 of file DateTools.cs.


The documentation for this class was generated from the following file: