You are here

function apachesolr_date_find_query_gap in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 apachesolr.module \apachesolr_date_find_query_gap()
  2. 6.2 apachesolr.module \apachesolr_date_find_query_gap()

Determine the gap in a date range query filter that we generated.

This function assumes that the start and end dates are the beginning and end of a single period: 1 year, month, day, hour, minute, or second (all date range query filters we generate meet this criteria). So, if the seconds are different, it is a second gap. If the seconds are the same (incidentally, they will also be 0) but the minutes are different, it is a minute gap. If the minutes are the same but hours are different, it's an hour gap. etc.

Parameters

$start: Start date as an ISO date string.

$end: End date as an ISO date string.

Return value

YEAR, MONTH, DAY, HOUR, MINUTE, or SECOND.

3 calls to apachesolr_date_find_query_gap()
apachesolr_date_facet_block in ./apachesolr.module
Helper function for displaying a date facet block.
apachesolr_date_format_range in ./apachesolr.module
Format the beginning of a date range query filter that we generated.
apachesolr_search_date_range in ./apachesolr_search.module

File

./apachesolr.module, line 902
Integration with the Apache Solr search application.

Code

function apachesolr_date_find_query_gap($start_iso, $end_iso) {
  $gaps = array(
    'SECOND' => 6,
    'MINUTE' => 5,
    'HOUR' => 4,
    'DAY' => 3,
    'MONTH' => 2,
    'YEAR' => 1,
  );
  $re = '@(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})@';
  if (preg_match($re, $start_iso, $start) && preg_match($re, $end_iso, $end)) {
    foreach ($gaps as $gap => $idx) {
      if ($start[$idx] != $end[$idx]) {
        return $gap;
      }
    }
  }

  // can't tell
  return 'YEAR';
}