DateField (Solr 3.6.2 API)
Keywords: org.apache.solr.schema.DateField class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.solr.schema
Class DateField

    java.lang.Object
      org.apache.solr.schema.FieldProperties
          org.apache.solr.schema.FieldType
              org.apache.solr.schema.PrimitiveFieldType
                  org.apache.solr.schema.DateField

Direct Known Subclasses:
  LegacyDateField, TrieDateField

    public class DateField

extends PrimitiveFieldType

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

- 1995-12-31T23:59:59Z
- 1995-12-31T23:59:59.9Z
- 1995-12-31T23:59:59.99Z
- 1995-12-31T23:59:59.999Z

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

Version:
  $Id: DateField.java 1298427 2012-03-08 15:22:27Z janhoy $
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` 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`

Fields inherited from class org.apache.solr.schema.FieldType
`analyzer, args, falseProperties, log, POLY_FIELD_SEPARATOR, queryAnalyzer, trueProperties, typeName`

Fields inherited from class org.apache.solr.schema.FieldProperties
`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 Summary
`DateField()`

Method Summary
`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

Methods inherited from class org.apache.solr.schema.PrimitiveFieldType
`init`

Methods inherited from class org.apache.solr.schema.FieldType
`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`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### UTC

    public static TimeZone UTC

### MATH_TZ

    protected static final TimeZone MATH_TZ

  TimeZone for DateMath (UTC)

### MATH_LOCALE

    protected static final Locale MATH_LOCALE

  Locale for DateMath (Locale.US)

### CANONICAL_TZ

    protected static final TimeZone CANONICAL_TZ

  Fixed TimeZone (UTC) needed for parsing/formating Dates in the canonical representation.

### CANONICAL_LOCALE

    protected static final Locale CANONICAL_LOCALE

  Fixed Locale needed for parsing/formating Milliseconds in the canonical representation.

### NOW

    protected static String NOW

### Z

    protected static char Z

Constructor Detail

### DateField

    public DateField()

Method Detail

### toInternal

    public String toInternal(String val)

  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.document.Fieldable)`

### parseMath

    public Date parseMath(Date now,
                          String val)

  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

### toInternal

    public String toInternal(Date val)

### indexedToReadable

    public String indexedToReadable(String indexedForm)

  Description copied from class: `FieldType`
  Given an indexed term, return the human readable representation

  Overrides:
    `indexedToReadable` in class `FieldType`

### toExternal

    public String toExternal(Fieldable f)

  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

  Throws:
    `ParseException`

### toObject

    public Date toObject(Fieldable f)

  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)

  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(XMLWriter xmlWriter,
                      String name,
                      Fieldable f)
               throws IOException

  Description copied from class: `FieldType`
  Renders the specified field as XML

  Specified by:
    `write` in class `FieldType`
  Throws:
    `IOException`

### write

    public void write(TextResponseWriter writer,
                      String name,
                      Fieldable f)
               throws IOException

  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)

  Thread safe method that can be used by subclasses to format a Date using the Internal representation.

### formatExternal

    public static String formatExternal(Date d)

  Return the standard human readable form of the date

### toExternal

    public String toExternal(Date d)

  See Also:
    `formatExternal(java.util.Date)`

### parseDate

    public static Date parseDate(String s)
                          throws ParseException

  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

  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)

  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)

  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)

  DateField specific range query

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD