Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Attributes
Lucene::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...

#include <DateTools.h>

+ Inheritance diagram for Lucene::DateTools:

Public Types

enum  Resolution {
  RESOLUTION_NULL , RESOLUTION_YEAR , RESOLUTION_MONTH , RESOLUTION_DAY ,
  RESOLUTION_HOUR , RESOLUTION_MINUTE , RESOLUTION_SECOND , RESOLUTION_MILLISECOND
}
 
enum  DateOrder { DATEORDER_LOCALE , DATEORDER_YMD , DATEORDER_DMY , DATEORDER_MDY }
 

Public Member Functions

virtual ~DateTools ()
 
virtual String getClassName ()
 
boost::shared_ptr< DateToolsshared_from_this ()
 
- Public Member Functions inherited from Lucene::LuceneObject
virtual ~LuceneObject ()
 
virtual void initialize ()
 Called directly after instantiation to create objects that depend on this object being fully constructed.
 
virtual LuceneObjectPtr clone (const LuceneObjectPtr &other=LuceneObjectPtr())
 Return clone of this object.
 
virtual int32_t hashCode ()
 Return hash code for this object.
 
virtual bool equals (const LuceneObjectPtr &other)
 Return whether two objects are equal.
 
virtual int32_t compareTo (const LuceneObjectPtr &other)
 Compare two objects.
 
virtual String toString ()
 Returns a string representation of the object.
 
- Public Member Functions inherited from Lucene::LuceneSync
virtual ~LuceneSync ()
 
virtual SynchronizePtr getSync ()
 Return this object synchronize lock.
 
virtual LuceneSignalPtr getSignal ()
 Return this object signal.
 
virtual void lock (int32_t timeout=0)
 Lock this object using an optional timeout.
 
virtual void unlock ()
 Unlock this object.
 
virtual bool holdsLock ()
 Returns true if this object is currently locked by current thread.
 
virtual void wait (int32_t timeout=0)
 Wait for signal using an optional timeout.
 
virtual void notifyAll ()
 Notify all threads waiting for signal.
 

Static Public Member Functions

static String _getClassName ()
 
static String dateToString (const boost::posix_time::ptime &date, Resolution resolution)
 Converts a Date to a string suitable for indexing.
 
static String timeToString (int64_t time, Resolution resolution)
 Converts a millisecond time to a string suitable for indexing.
 
static int64_t stringToTime (const 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 boost::posix_time::ptime stringToDate (const String &dateString)
 Converts a string produced by timeToString or dateToString back to a time, represented as a ptime object.
 
static boost::posix_time::ptime round (const boost::posix_time::ptime &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 int64_t round (int64_t 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.
 
static void setDateOrder (DateTools::DateOrder order)
 Allow overriding of date ordering.
 
static DateTools::DateOrder getDateOrder (std::locale locale=std::locale())
 Return date ordering based on given locale (or overridden in setDateOrder(DateTools::DateOrder)).
 
static boost::posix_time::ptime parseDate (const String &dateString, std::locale locale=std::locale())
 Parse a given date using locale date format.
 

Static Protected Attributes

static DateOrder dateOrder
 

Additional Inherited Members

- Protected Member Functions inherited from Lucene::LuceneObject
 LuceneObject ()
 
- Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr objectLock
 
LuceneSignalPtr objectSignal
 

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 Date or Calendar, just get the unix timestamp as long using Date#getTime or Calendar#getTimeInMillis and index this as a numeric value with NumericField and use NumericRangeQuery to query it.

Member Enumeration Documentation

◆ DateOrder

Enumerator
DATEORDER_LOCALE 
DATEORDER_YMD 
DATEORDER_DMY 
DATEORDER_MDY 

◆ Resolution

Enumerator
RESOLUTION_NULL 
RESOLUTION_YEAR 
RESOLUTION_MONTH 
RESOLUTION_DAY 
RESOLUTION_HOUR 
RESOLUTION_MINUTE 
RESOLUTION_SECOND 
RESOLUTION_MILLISECOND 

Constructor & Destructor Documentation

◆ ~DateTools()

virtual Lucene::DateTools::~DateTools ( )
virtual

Member Function Documentation

◆ _getClassName()

static String Lucene::DateTools::_getClassName ( )
inlinestatic

◆ dateToString()

static String Lucene::DateTools::dateToString ( const boost::posix_time::ptime &  date,
Resolution  resolution 
)
static

Converts a Date to a string suitable for indexing.

Parameters
datethe date to be converted
resolutionthe desired resolution
Returns
a string in format yyyyMMddHHmmssSSS or shorter, depending on resolution; using GMT as timezone

◆ getClassName()

virtual String Lucene::DateTools::getClassName ( )
inlinevirtual

◆ getDateOrder()

static DateTools::DateOrder Lucene::DateTools::getDateOrder ( std::locale  locale = std::locale())
static

Return date ordering based on given locale (or overridden in setDateOrder(DateTools::DateOrder)).

◆ parseDate()

static boost::posix_time::ptime Lucene::DateTools::parseDate ( const String &  dateString,
std::locale  locale = std::locale() 
)
static

Parse a given date using locale date format.

Parameters
dateStringthe date string to be converted
localethe locale to use for parsing
Returns
the parsed time as a ptime object

◆ round() [1/2]

static boost::posix_time::ptime Lucene::DateTools::round ( const boost::posix_time::ptime &  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
resolutionThe desired resolution of the date to be returned
Returns
the date with all values more precise than resolution set to 0 or 1

◆ round() [2/2]

static int64_t Lucene::DateTools::round ( int64_t  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
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

◆ setDateOrder()

static void Lucene::DateTools::setDateOrder ( DateTools::DateOrder  order)
static

Allow overriding of date ordering.

◆ shared_from_this()

boost::shared_ptr< DateTools > Lucene::DateTools::shared_from_this ( )
inline

◆ stringToDate()

static boost::posix_time::ptime Lucene::DateTools::stringToDate ( const String &  dateString)
static

Converts a string produced by timeToString or dateToString back to a time, represented as a ptime object.

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

◆ stringToTime()

static int64_t Lucene::DateTools::stringToTime ( const 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

◆ timeToString()

static String Lucene::DateTools::timeToString ( int64_t  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
Returns
a string in format yyyyMMddHHmmssSSS or shorter, depending on resolution; using GMT as timezone

Field Documentation

◆ dateOrder

DateOrder Lucene::DateTools::dateOrder
staticprotected

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

clucene.sourceforge.net