public class DateField extends PrimitiveFieldType
Date Format for the XML, incoming and outgoing:
A date field shall be of the form 1995-12-31T23:59:59Z The trailing "Z" designates UTC time and is mandatory (See below for an explanation of UTC). Optional fractional seconds are allowed, as long as they do not end in a trailing 0 (but any precision beyond milliseconds will be ignored). All other parts are mandatory.
This format was derived to be standards compliant (ISO 8601) and is a more restricted form of the canonical representation of dateTime from XML schema part 2. Examples...
Note that DateField is lenient with regards to parsing fractional seconds that end in trailing zeros and will ensure that those values are indexed in the correct canonical format.
This FieldType also supports incoming "Date Math" strings for computing
values by adding/rounding internals of time relative either an explicit
datetime (in the format specified above) or the literal string "NOW",
ie: "NOW+1YEAR", "NOW/DAY", "1995-12-31T23:59:59.999Z+5MINUTES", etc...
-- see DateMathParser
for more examples.
Explanation of "UTC"...
"In 1970 the Coordinated Universal Time system was devised by an international advisory group of technical experts within the International Telecommunication Union (ITU). The ITU felt it was best to designate a single abbreviation for use in all languages in order to minimize confusion. Since unanimous agreement could not be achieved on using either the English word order, CUT, or the French word order, TUC, the acronym UTC was chosen as a compromise."
FieldType.DefaultAnalyzer
Modifier and Type | Field and Description |
---|---|
protected static Locale |
CANONICAL_LOCALE
Fixed Locale needed for parsing/formating Milliseconds in the
canonical representation.
|
protected static TimeZone |
CANONICAL_TZ
Fixed TimeZone (UTC) needed for parsing/formating Dates in the
canonical representation.
|
protected static Locale |
MATH_LOCALE
Locale for DateMath (Locale.US)
|
protected static TimeZone |
MATH_TZ
TimeZone for DateMath (UTC)
|
protected static String |
NOW |
static TimeZone |
UTC |
protected static char |
Z |
analyzer, args, falseProperties, log, POLY_FIELD_SEPARATOR, queryAnalyzer, trueProperties, typeName
BINARY, INDEXED, MULTIVALUED, OMIT_NORMS, OMIT_POSITIONS, OMIT_TF_POSITIONS, REQUIRED, SORT_MISSING_FIRST, SORT_MISSING_LAST, STORE_TERMOFFSETS, STORE_TERMPOSITIONS, STORE_TERMVECTORS, STORED, TOKENIZED
Constructor and Description |
---|
DateField() |
Modifier and Type | Method and Description |
---|---|
protected String |
formatDate(Date d)
Thread safe method that can be used by subclasses to format a Date
using the Internal representation.
|
static String |
formatExternal(Date d)
Return the standard human readable form of the date
|
Query |
getRangeQuery(QParser parser,
SchemaField sf,
Date part1,
Date part2,
boolean minInclusive,
boolean maxInclusive)
DateField specific range query
|
SortField |
getSortField(SchemaField field,
boolean reverse)
Returns the SortField instance that should be used to sort fields
of this type.
|
protected DateFormat |
getThreadLocalDateFormat()
Deprecated.
- use formatDate(Date) instead
|
ValueSource |
getValueSource(SchemaField field,
QParser parser)
called to get the default value source (normally, from the
Lucene FieldCache.)
|
String |
indexedToReadable(String indexedForm)
Given an indexed term, return the human readable representation
|
static Date |
parseDate(String s)
Thread safe method that can be used by subclasses to parse a Date
that is already in the internal representation
|
Date |
parseDateLenient(String s,
SolrQueryRequest req)
Parse a date string in the standard format, or any supported by DateUtil.parseDate
|
Date |
parseMath(Date now,
String val)
Parses a String which may be a date (in the standard format)
followed by an optional math expression.
|
Date |
parseMathLenient(Date now,
String val,
SolrQueryRequest req)
Parses a String which may be a date
followed by an optional math expression.
|
String |
toExternal(Date d) |
String |
toExternal(Fieldable f)
Convert the stored-field format to an external (string, human readable)
value
|
String |
toInternal(Date val) |
String |
toInternal(String val)
Convert an external value (from XML update command or from query string)
into the internal format for both storing and indexing (which can be modified by any analyzers).
|
Date |
toObject(Fieldable f)
Convert the stored-field format to an external object.
|
Date |
toObject(String indexedForm) |
void |
write(TextResponseWriter writer,
String name,
Fieldable f)
calls back to TextResponseWriter to write the field value
|
void |
write(XMLWriter xmlWriter,
String name,
Fieldable f)
Renders the specified field as XML
|
init
createField, createField, createFields, getAnalyzer, getArg, getFieldIndex, getFieldQuery, getFieldStore, getFieldTermVec, getIndexOptions, getQueryAnalyzer, getRangeQuery, getStringSort, getTypeName, getValueSource, hasProperty, isMultiValued, isPolyField, isTokenized, multiValuedFieldCache, readableToIndexed, restrictProps, setAnalyzer, setQueryAnalyzer, storedToIndexed, storedToReadable, toString
public static TimeZone UTC
protected static final TimeZone MATH_TZ
protected static final Locale MATH_LOCALE
protected static final TimeZone CANONICAL_TZ
protected static final Locale CANONICAL_LOCALE
protected static String NOW
protected static char Z
public String toInternal(String val)
FieldType
toInternal
in class FieldType
FieldType.toExternal(org.apache.lucene.document.Fieldable)
public Date parseMath(Date now, String val)
now
- an optional fixed date to use as "NOW" in the DateMathParserval
- the string to parsepublic String indexedToReadable(String indexedForm)
FieldType
indexedToReadable
in class FieldType
public String toExternal(Fieldable f)
FieldType
toExternal
in class FieldType
FieldType.toInternal(java.lang.String)
public Date toObject(String indexedForm) throws ParseException
ParseException
public Date toObject(Fieldable f)
FieldType
toObject
in class FieldType
FieldType.toInternal(java.lang.String)
public SortField getSortField(SchemaField field, boolean reverse)
FieldType
getSortField
in class FieldType
SchemaField.checkSortability()
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException
FieldType
write
in class FieldType
IOException
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException
FieldType
write
in class FieldType
IOException
@Deprecated protected DateFormat getThreadLocalDateFormat()
protected String formatDate(Date d)
public static String formatExternal(Date d)
public String toExternal(Date d)
formatExternal(java.util.Date)
public static Date parseDate(String s) throws ParseException
ParseException
public Date parseDateLenient(String s, SolrQueryRequest req) throws ParseException
ParseException
public Date parseMathLenient(Date now, String val, SolrQueryRequest req)
now
- an optional fixed date to use as "NOW" in the DateMathParserval
- the string to parsepublic ValueSource getValueSource(SchemaField field, QParser parser)
FieldType
getValueSource
in class FieldType
public Query getRangeQuery(QParser parser, SchemaField sf, Date part1, Date part2, boolean minInclusive, boolean maxInclusive)