Lucene++ - a full-featured, c++ search engine
API Documentation
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>
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< DateTools > | shared_from_this () |
![]() | |
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. | |
![]() | |
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 | |
![]() | |
LuceneObject () | |
![]() | |
SynchronizePtr | objectLock |
LuceneSignalPtr | objectSignal |
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.
|
virtual |
|
inlinestatic |
|
static |
Converts a Date to a string suitable for indexing.
date | the date to be converted |
resolution | the desired resolution |
|
inlinevirtual |
|
static |
Return date ordering based on given locale (or overridden in setDateOrder(DateTools::DateOrder)
).
|
static |
Parse a given date using locale date format.
dateString | the date string to be converted |
locale | the locale to use for parsing |
|
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.
resolution | The desired resolution of the date to be returned |
|
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.
resolution | The desired resolution of the date to be returned |
|
static |
Allow overriding of date ordering.
|
inline |
|
static |
Converts a string produced by timeToString or dateToString back to a time, represented as a ptime object.
dateString | the date string to be converted |
|
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.
dateString | the date string to be converted |
|
static |
Converts a millisecond time to a string suitable for indexing.
time | the date expressed as milliseconds since January 1, 1970, 00:00:00 GMT |
resolution | the desired resolution |
|
staticprotected |