upadted to 1.8

This commit is contained in:
Bachir Soussi Chiadmi
2013-09-26 15:49:26 +02:00
parent e0ae80791b
commit 128640cd15
52 changed files with 2604 additions and 1015 deletions

View File

@@ -128,8 +128,10 @@ class SearchApiFacetapiAdapter extends FacetapiAdapter {
* search_api_current_search(). Or NULL, if no match was found.
*/
public function getCurrentSearch() {
// Even if this fails once, there might be a search query later in the page
// request. We therefore don't store anything in $this->current_search in
// case of failure, but just try again if the method is called again.
if (!isset($this->current_search)) {
$this->current_search = FALSE;
$index_id = $this->info['instance'];
// There is currently no way to configure the "current search" block to
// show on a per-searcher basis as we do with the facets. Therefore we
@@ -143,7 +145,7 @@ class SearchApiFacetapiAdapter extends FacetapiAdapter {
}
}
}
return $this->current_search ? $this->current_search : NULL;
return $this->current_search;
}
/**
@@ -172,16 +174,6 @@ class SearchApiFacetapiAdapter extends FacetapiAdapter {
// properly.
$keys = '[' . t('complex query') . ']';
}
elseif (!$keys) {
// If a base path other than the current one is set, we assume that we
// shouldn't report on the current search. Highly hack-y, of course.
if ($search[0]->getOption('search_api_base_path', $_GET['q']) !== $_GET['q']) {
return NULL;
}
// Work-around since Facet API won't show the "Current search" block
// without keys.
$keys = '[' . t('all items') . ']';
}
drupal_alter('search_api_facetapi_keys', $keys, $search[0]);
return $keys;
}
@@ -238,5 +230,25 @@ class SearchApiFacetapiAdapter extends FacetapiAdapter {
'#value' => array(),
);
}
// Add a granularity option to date query types.
if (isset($facet['query type']) && $facet['query type'] == 'date') {
$granularity_options = array(
FACETAPI_DATE_YEAR => t('Years'),
FACETAPI_DATE_MONTH => t('Months'),
FACETAPI_DATE_DAY => t('Days'),
FACETAPI_DATE_HOUR => t('Hours'),
FACETAPI_DATE_MINUTE => t('Minutes'),
FACETAPI_DATE_SECOND => t('Seconds'),
);
$form['global']['date_granularity'] = array(
'#type' => 'select',
'#title' => t('Granularity'),
'#description' => t('Determine the maximum drill-down level'),
'#options' => $granularity_options,
'#default_value' => isset($options['date_granularity']) ? $options['date_granularity'] : FACETAPI_DATE_MINUTE,
);
}
}
}

View File

@@ -85,8 +85,8 @@ class SearchApiFacetapiDate extends SearchApiFacetapiTerm implements FacetapiQue
// this method.
// Executes query, iterates over results.
if (isset($results['search_api_facets']) && isset($results['search_api_facets'][$this->facet['field']])) {
$values = $results['search_api_facets'][$this->facet['field']];
if (isset($results['search_api_facets']) && isset($results['search_api_facets'][$this->facet['name']])) {
$values = $results['search_api_facets'][$this->facet['name']];
foreach ($values as $value) {
if ($value['count']) {
$filter = $value['filter'];
@@ -115,20 +115,24 @@ class SearchApiFacetapiDate extends SearchApiFacetapiTerm implements FacetapiQue
}
}
// Get the finest level of detail we're allowed to drill down to.
$settings = $facet->getSettings()->settings;
$granularity = isset($settings['date_granularity']) ? $settings['date_granularity'] : FACETAPI_DATE_MINUTE;
// Gets active facets, starts building hierarchy.
$parent = $gap = NULL;
foreach ($this->adapter->getActiveItems($this->facet) as $value => $item) {
// If the item is active, the count is the result set count.
$build[$value] = array('#count' => $total);
// Gets next "gap" increment, minute being the lowest we can go.
// Gets next "gap" increment.
if ($value[0] != '[' || $value[strlen($value) - 1] != ']' || !($pos = strpos($value, ' TO '))) {
continue;
}
$start = substr($value, 1, $pos);
$end = substr($value, $pos + 4, -1);
$date_gap = facetapi_get_date_gap($start, $end);
$gap = facetapi_get_next_date_gap($date_gap, FACETAPI_DATE_MINUTE);
$gap = facetapi_get_next_date_gap($date_gap, $granularity);
// If there is a previous item, there is a parent, uses a reference so the
// arrays are populated when they are updated.
@@ -150,9 +154,24 @@ class SearchApiFacetapiDate extends SearchApiFacetapiTerm implements FacetapiQue
if (NULL === $parent) {
if (count($raw_values) > 1) {
$gap = facetapi_get_timestamp_gap(min($timestamps), max($timestamps));
// Array of numbers used to determine whether the next gap is smaller than
// the minimum gap allowed in the drilldown.
$gap_numbers = array(
FACETAPI_DATE_YEAR => 6,
FACETAPI_DATE_MONTH => 5,
FACETAPI_DATE_DAY => 4,
FACETAPI_DATE_HOUR => 3,
FACETAPI_DATE_MINUTE => 2,
FACETAPI_DATE_SECOND => 1,
);
// Gets gap numbers for both the gap and minimum gap, checks if the gap
// is within the limit set by the $granularity parameter.
if ($gap_numbers[$gap] < $gap_numbers[$granularity]) {
$gap = $granularity;
}
}
else {
$gap = FACETAPI_DATE_HOUR;
$gap = $granularity;
}
}

View File

@@ -120,8 +120,8 @@ class SearchApiFacetapiTerm extends FacetapiQueryType implements FacetapiQueryTy
$search = search_api_current_search($search_id);
$build = array();
$results = $search[1];
if (isset($results['search_api_facets']) && isset($results['search_api_facets'][$this->facet['field']])) {
$values = $results['search_api_facets'][$this->facet['field']];
if (isset($results['search_api_facets']) && isset($results['search_api_facets'][$this->facet['name']])) {
$values = $results['search_api_facets'][$this->facet['name']];
foreach ($values as $value) {
$filter = $value['filter'];
// As Facet API isn't really suited for our native facet filter