11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Working with Dates<br />

Date Formatting<br />

<strong>Solr</strong>'s date fields ( TrieDateField and DateRangeField) represents a point in time with millisecond<br />

precision. The format used is a restricted form of the canonical representation of dateTime in the XML Schema<br />

specification – a restricted subset of ISO-8601. For those familiar with Java 8, <strong>Solr</strong> uses DateTimeFormatter.IS<br />

O_INSTANT for formatting, and parsing too with "leniency".<br />

YYYY-MM-DDThh:mm:ssZ<br />

YYYY is the year.<br />

MM is the month.<br />

DD is the day of the month.<br />

hh is the hour of the day as on a 24-hour clock.<br />

mm is minutes.<br />

ss is seconds.<br />

Z is a literal 'Z' character indicating that this string representation of the date is in UTC<br />

Note that no time zone can be specified; the String representations of dates is always expressed in Coordinated<br />

Universal Time (UTC). Here is an example value:<br />

1972-05-20T17:33:18Z<br />

You can optionally include fractional seconds if you wish, although any precision beyond milliseconds will be<br />

ignored. Here are example values with sub-seconds:<br />

1972-05-20T17:33:18.772Z<br />

1972-05-20T17:33:18.77Z<br />

1972-05-20T17:33:18.7Z<br />

There must be a leading '-' for dates prior to year 0000, and <strong>Solr</strong> will format dates with a leading ' + ' for years<br />

after 9999. Year 0000 is considered year 1 BC; there is no such thing as year 0 AD or BC.<br />

Query escaping may be required<br />

As you can see, the date format includes colon characters separating the hours, minutes, and seconds.<br />

Because the colon is a special character to <strong>Solr</strong>'s most common query parsers, escaping is sometimes<br />

required, depending on exactly what you are trying to do.<br />

This is normally an invalid query:<br />

datefield:1972-05-20T17:33:18.772Z<br />

These are valid queries:<br />

datefield:1972-05-20T17\:33\:18.772Z<br />

datefield:"1972-05-20T17:33:18.772Z"<br />

datefield:[1972-05-20T17:33:18.772 TO *]<br />

Date Range Formatting<br />

<strong>Solr</strong>'s DateRangeField supports the same point in time date syntax described above (with date math describe<br />

d below) and more to express date ranges. One class of examples is truncated dates, which represent the entire<br />

date span to the precision indicated. The other class uses the range syntax ([ TO ]). Here are some<br />

examples:<br />

2000-11 – The entire month of November, 2000.<br />

2000-11T13 – Likewise but for the 13th hour of the day (1pm-2pm).<br />

<strong>Apache</strong> <strong>Solr</strong> <strong>Reference</strong> <strong>Guide</strong> <strong>6.0</strong><br />

57

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!