This is a wiki-style Islandora knowledge base that anyone can edit.
Editing
Dates in Drupal and Solr
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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 == Core Drupal provides field types that store Dates, but they're not very appropriate for metadata purposes. === Date field type === 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. [https://www.drupal.org/project/facets/issues/3153622 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 === 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 == Islandora provides a great field type for metadata, but it is not ideal in its ability to be indexed by Solr. === Controlled Access Terms === 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 == Solr supports both point dates and date ranges, and can easily compute date range queries over date range fields. === Date types === Solr has a great documentation page on [https://solr.apache.org/guide/8_11/working-with-dates.html 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 === 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 === 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 == === Facets Range Datepicker Widget === [https://www.drupal.org/project/facets_range_datepicker_widget 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 === [https://www.drupal.org/project/facets_date_range 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 === [https://www.drupal.org/project/facets_date_range_picker 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 [[Category:Search]]
Summary:
Please note that all contributions to Islandora Knowledge Base are considered to be released under the Creative Commons Zero (Public Domain) (see
Project:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
English
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information