This is a wiki-style Islandora knowledge base that anyone can edit.

Dates in Drupal and Solr

From Islandora Knowledge Base
Jump to navigation Jump to search

You want to be able to represent complex date information in Islandora. You also want to be able to search by date (ranges) in Solr.

Core Drupal Field Types[edit | edit source]

Core Drupal provides field types that store Dates, but they're not very appropriate for metadata purposes.

Date field type[edit | edit source]

So core you can't imagine living without it, there is a "Date" field type. It takes a single date, either entered as a date (down to the day) or a date with a time. It can be displayed in arbitary PHP date formats, and easily indexes into Solr as a date field.

As a Facet, it can be displayed at year, year-month, or year-month-day granularity. There is a "slider" (lets you drag a widget to specify a year range) but since JqueryUI was deprecated, it needs a patch. Seth Shaw wrote one.

Problems:

Much date metadata cannot be specified down to the day because it's:

  • approximate or uncertain
  • specified less precisely - to a month, year, decade, century, even season
  • specified as a range, closed or open ended

These can be represented in EDTF; see below.

Datetime range[edit | edit source]

The Datetime range module is included with Core but not enabled by default. It enables a "Date range" field type that can be set as "Date and time", "Date only", or "All day". It takes two dates, and the default widget is a datepicker. The dates must be specified down to the day, making this inappropriate for metadata as it has many the same problems as (point) Dates.

It can be indexed into solr as two dates - the start date and the end date, or as a "Date range" solr field type.

It is not possible to use the Facets module to create a facet with this field, as "The field types supported [by Facets] are boolean, date, decimal, integer and string."

Islandora Field Types[edit | edit source]

Islandora provides a great field type for metadata, but it is not ideal in its ability to be indexed by Solr.

Controlled Access Terms[edit | edit source]

Provides an EDTF date field type. It accepts (and validates) string in EDTF date format. This handles most of the metadata use cases (above) except arbitrary strings (e.g. Edo Period).

It can be indexed in solr as a string (not very useful, except maybe for sorting?) and also as a year-or-range-of-years. This field is configured and enabled under Search API's "Processors" first, then the usual way in Search API "Fields". It can be set up as a facet.


Solr[edit | edit source]

Solr supports both point dates and date ranges, and can easily compute date range queries over date range fields.

Date types[edit | edit source]

Solr has a great documentation page on Working with dates. As of 8.11, there is a `DatePointField` and a `DateRangeField`. The DatePointField is a point in time with millisecond precision. The DateRangeField allows values expressed as truncated dates (2000-11, -0009) and also ranges ([2000-11-01 TO 2014-12-01], [* TO 2014-12-01]).

Date queries[edit | edit source]

You can search using a query containing a date range over DatePointField's, and it finds dates within that range. This is what happens with the Drupal core Date field when it is used in Facets.

For searching using DateRangeFields, Solr provides three predicates relating the indexed data to the query range: `Intersects`, `Contains`, and `Within`. To get the most out of a metadata search, we likely want to use "Intersects" as it encompasses "Contains" and "Within". It can be used in the Solr Admin Interface as:

`fq={!field f=dateRangeFieldName op=Intersects}[2013 TO 2018]`

Limitations[edit | edit source]

It appears that Solr cannot process dates trunctated to decades, centuries, or millennia (as can be represented in EDTF). It also cannot represent approximation or uncertainty, as can be expected when binary date math is required.

External Date Faceting Modules[edit | edit source]

Facets Range Datepicker Widget[edit | edit source]

Facets Range Datepicker Widget on Drupal.org. This module offers two new "widgets" for facets:

  • Datepicker
  • Range Datepicker

The datepicker widget seemed to be broken or missing instructions. When I enabled it in a facet, NO facets show and the search results are empty.

The range datepicker worked, providing a widget with two fields, each lets you use datepicker to pick a date. Then the range is provided to Solr as a range query and it works. When it does this, the value it puts in the URL is just a timestamp, not a formatted date.

Facets Date Range[edit | edit source]

Facets Date Range on Drupal.org. Appears to provide a facet module to let users select date ranges. The module seems to be broken or missing instructions. When enabled, no facets show and the search results are empty. I do not know that it handles solr dateranges.

Facets Date Range Picker[edit | edit source]

Facets Date Range Picker on Drupal.org. Very simplistic, provides the following fixed list of date ranges:

   Today
   Tomorrow
   This weekend
   This long weekend
   Next 7 days
   Next 14 days
   Next 30 days
   Next 3 months
   Next 6 months
   Next year