org.apache.solr.schema
Class DateField

java.lang.Object
  extended by org.apache.solr.schema.FieldProperties
      extended by org.apache.solr.schema.FieldType
          extended by org.apache.solr.schema.PrimitiveFieldType
              extended by org.apache.solr.schema.DateField
All Implemented Interfaces:
DateValueFieldType
Direct Known Subclasses:
TrieDateField

Deprecated. TrieDateField is recomended for all new schemas

public class DateField
extends PrimitiveFieldType
implements DateValueFieldType

FieldType that can represent any Date/Time with millisecond precision.

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.

NOTE: Allthough it is possible to configure a DateField instance with a default value of "NOW" to compute a timestamp of when the document was indexed, this is not advisable when using SolrCloud since each replica of the document may compute a slightly different value. TimestampUpdateProcessorFactory is recomended instead.

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."

See Also:
XML schema part 2

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.solr.schema.FieldType
FieldType.DefaultAnalyzer
 
Field Summary
protected static Locale CANONICAL_LOCALE
          Deprecated. Fixed Locale needed for parsing/formating Milliseconds in the canonical representation.
protected static TimeZone CANONICAL_TZ
          Deprecated. Fixed TimeZone (UTC) needed for parsing/formating Dates in the canonical representation.
protected static Locale MATH_LOCALE
          Deprecated. use DateMathParser.DEFAULT_MATH_LOCALE
protected static TimeZone MATH_TZ
          Deprecated. use DateMathParser.DEFAULT_MATH_TZ
protected static String NOW
          Deprecated.  
static TimeZone UTC
          Deprecated.  
protected static char Z
          Deprecated.  
 
Fields inherited from class org.apache.solr.schema.FieldType
analyzer, ANALYZER, args, CHAR_FILTER, CHAR_FILTERS, CLASS_NAME, docValuesFormat, falseProperties, FILTER, FILTERS, INDEX, INDEX_ANALYZER, log, MULTI_TERM, MULTI_TERM_ANALYZER, POLY_FIELD_SEPARATOR, postingsFormat, properties, QUERY, QUERY_ANALYZER, queryAnalyzer, similarity, SIMILARITY, similarityFactory, TOKENIZER, trueProperties, TYPE, TYPE_NAME, typeName
 
Fields inherited from class org.apache.solr.schema.FieldProperties
BINARY, DOC_VALUES, INDEXED, MULTIVALUED, OMIT_NORMS, OMIT_POSITIONS, OMIT_TF_POSITIONS, REQUIRED, SORT_MISSING_FIRST, SORT_MISSING_LAST, STORE_OFFSETS, STORE_TERMOFFSETS, STORE_TERMPOSITIONS, STORE_TERMVECTORS, STORED, TOKENIZED
 
Constructor Summary
DateField()
          Deprecated.  
 
Method Summary
 IndexableField createField(SchemaField field, Object value, float boost)
          Deprecated. Used for adding a document when a field needs to be created from a type and a string.
protected  String formatDate(Date d)
          Deprecated. Thread safe method that can be used by subclasses to format a Date using the Internal representation.
static String formatExternal(Date d)
          Deprecated. Return the standard human readable form of the date
 Query getRangeQuery(QParser parser, SchemaField sf, Date part1, Date part2, boolean minInclusive, boolean maxInclusive)
          Deprecated. DateField specific range query
 SortField getSortField(SchemaField field, boolean reverse)
          Deprecated. 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)
          Deprecated. called to get the default value source (normally, from the Lucene FieldCache.)
 CharsRef indexedToReadable(BytesRef input, CharsRef charsRef)
          Deprecated. Given an indexed term, append the human readable representation
 String indexedToReadable(String indexedForm)
          Deprecated. Given an indexed term, return the human readable representation
static Date parseDate(String s)
          Deprecated. 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)
          Deprecated. Parse a date string in the standard format, or any supported by DateUtil.parseDate
 Date parseMath(Date now, String val)
          Deprecated. 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)
          Deprecated. Parses a String which may be a date followed by an optional math expression.
 String toExternal(Date d)
          Deprecated.  
 String toExternal(IndexableField f)
          Deprecated. Convert the stored-field format to an external (string, human readable) value
 String toInternal(Date val)
          Deprecated.  
 String toInternal(String val)
          Deprecated. 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(IndexableField f)
          Deprecated. Convert the stored-field format to an external object.
 Date toObject(String indexedForm)
          Deprecated.  
 void write(TextResponseWriter writer, String name, IndexableField f)
          Deprecated. calls back to TextResponseWriter to write the field value
 
Methods inherited from class org.apache.solr.schema.PrimitiveFieldType
init
 
Methods inherited from class org.apache.solr.schema.FieldType
checkSchemaField, createField, createFields, getAnalyzer, getAnalyzerProperties, getClassArg, getDocValuesFormat, getFieldQuery, getIndexOptions, getNamedPropertyValues, getNonFieldPropertyArgs, getNumericType, getPostingsFormat, getQueryAnalyzer, getRangeQuery, getRewriteMethod, getSimilarity, getSimilarityFactory, getStringSort, getTypeName, hasProperty, isExplicitAnalyzer, isExplicitQueryAnalyzer, isMultiValued, isPolyField, isTokenized, multiValuedFieldCache, readableToIndexed, readableToIndexed, restrictProps, setAnalyzer, setArgs, setIsExplicitAnalyzer, setIsExplicitQueryAnalyzer, setQueryAnalyzer, setSimilarity, storedToIndexed, storedToReadable, toObject, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UTC

public static TimeZone UTC
Deprecated. 

MATH_TZ

protected static final TimeZone MATH_TZ
Deprecated. use DateMathParser.DEFAULT_MATH_TZ
No longer used

See Also:
DateMathParser.DEFAULT_MATH_TZ

MATH_LOCALE

protected static final Locale MATH_LOCALE
Deprecated. use DateMathParser.DEFAULT_MATH_LOCALE
No longer used

See Also:
DateMathParser.DEFAULT_MATH_LOCALE

CANONICAL_TZ

protected static final TimeZone CANONICAL_TZ
Deprecated. 
Fixed TimeZone (UTC) needed for parsing/formating Dates in the canonical representation.


CANONICAL_LOCALE

protected static final Locale CANONICAL_LOCALE
Deprecated. 
Fixed Locale needed for parsing/formating Milliseconds in the canonical representation.


NOW

protected static String NOW
Deprecated. 

Z

protected static char Z
Deprecated. 
Constructor Detail

DateField

public DateField()
Deprecated. 
Method Detail

toInternal

public String toInternal(String val)
Deprecated. 
Description copied from class: FieldType
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).

Overrides:
toInternal in class FieldType
See Also:
FieldType.toExternal(org.apache.lucene.index.IndexableField)

parseMath

public Date parseMath(Date now,
                      String val)
Deprecated. 
Parses a String which may be a date (in the standard format) followed by an optional math expression.

Parameters:
now - an optional fixed date to use as "NOW" in the DateMathParser
val - the string to parse

createField

public IndexableField createField(SchemaField field,
                                  Object value,
                                  float boost)
Deprecated. 
Description copied from class: FieldType
Used for adding a document when a field needs to be created from a type and a string.

By default, the indexed value is the same as the stored value (taken from toInternal()). Having a different representation for external, internal, and indexed would present quite a few problems given the current Lucene architecture. An analyzer for adding docs would need to translate internal->indexed while an analyzer for querying would need to translate external->indexed.

The only other alternative to having internal==indexed would be to have internal==external. In this case, toInternal should convert to the indexed representation, toExternal() should do nothing, and createField() should *not* call toInternal, but use the external value and set tokenized=true to get Lucene to convert to the internal(indexed) form.

:TODO: clean up and clarify this explanation.

Overrides:
createField in class FieldType
See Also:
FieldType.toInternal(java.lang.String)

toInternal

public String toInternal(Date val)
Deprecated. 

indexedToReadable

public String indexedToReadable(String indexedForm)
Deprecated. 
Description copied from class: FieldType
Given an indexed term, return the human readable representation

Overrides:
indexedToReadable in class FieldType

indexedToReadable

public CharsRef indexedToReadable(BytesRef input,
                                  CharsRef charsRef)
Deprecated. 
Description copied from class: FieldType
Given an indexed term, append the human readable representation

Overrides:
indexedToReadable in class FieldType

toExternal

public String toExternal(IndexableField f)
Deprecated. 
Description copied from class: FieldType
Convert the stored-field format to an external (string, human readable) value

Overrides:
toExternal in class FieldType
See Also:
FieldType.toInternal(java.lang.String)

toObject

public Date toObject(String indexedForm)
              throws ParseException
Deprecated. 
Throws:
ParseException

toObject

public Date toObject(IndexableField f)
Deprecated. 
Description copied from class: FieldType
Convert the stored-field format to an external object.

Overrides:
toObject in class FieldType
See Also:
FieldType.toInternal(java.lang.String)

getSortField

public SortField getSortField(SchemaField field,
                              boolean reverse)
Deprecated. 
Description copied from class: FieldType
Returns the SortField instance that should be used to sort fields of this type.

Specified by:
getSortField in class FieldType
See Also:
SchemaField.checkSortability()

write

public void write(TextResponseWriter writer,
                  String name,
                  IndexableField f)
           throws IOException
Deprecated. 
Description copied from class: FieldType
calls back to TextResponseWriter to write the field value

Specified by:
write in class FieldType
Throws:
IOException

getThreadLocalDateFormat

@Deprecated
protected DateFormat getThreadLocalDateFormat()
Deprecated. - use formatDate(Date) instead

Returns a formatter that can be use by the current thread if needed to convert Date objects to the Internal representation. Only the format(Date) can be used safely.


formatDate

protected String formatDate(Date d)
Deprecated. 
Thread safe method that can be used by subclasses to format a Date using the Internal representation.


formatExternal

public static String formatExternal(Date d)
Deprecated. 
Return the standard human readable form of the date


toExternal

public String toExternal(Date d)
Deprecated. 
See Also:
formatExternal(java.util.Date)

parseDate

public static Date parseDate(String s)
                      throws ParseException
Deprecated. 
Thread safe method that can be used by subclasses to parse a Date that is already in the internal representation

Throws:
ParseException

parseDateLenient

public Date parseDateLenient(String s,
                             SolrQueryRequest req)
                      throws ParseException
Deprecated. 
Parse a date string in the standard format, or any supported by DateUtil.parseDate

Throws:
ParseException

parseMathLenient

public Date parseMathLenient(Date now,
                             String val,
                             SolrQueryRequest req)
Deprecated. 
Parses a String which may be a date followed by an optional math expression.

Parameters:
now - an optional fixed date to use as "NOW" in the DateMathParser
val - the string to parse

getValueSource

public ValueSource getValueSource(SchemaField field,
                                  QParser parser)
Deprecated. 
Description copied from class: FieldType
called to get the default value source (normally, from the Lucene FieldCache.)

Overrides:
getValueSource in class FieldType

getRangeQuery

public Query getRangeQuery(QParser parser,
                           SchemaField sf,
                           Date part1,
                           Date part2,
                           boolean minInclusive,
                           boolean maxInclusive)
Deprecated. 
DateField specific range query



Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.