upadted to 1.8
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -9,9 +9,9 @@ files[] = plugins/facetapi/adapter.inc
|
||||
files[] = plugins/facetapi/query_type_term.inc
|
||||
files[] = plugins/facetapi/query_type_date.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-01-09
|
||||
version = "7.x-1.4"
|
||||
; Information added by drupal.org packaging script on 2013-09-01
|
||||
version = "7.x-1.8"
|
||||
core = "7.x"
|
||||
project = "search_api"
|
||||
datestamp = "1357726719"
|
||||
datestamp = "1378025826"
|
||||
|
||||
|
@@ -65,6 +65,9 @@ function search_api_facetapi_facetapi_searcher_info() {
|
||||
'supports facet mincount' => TRUE,
|
||||
'include default facets' => FALSE,
|
||||
);
|
||||
if (($entity_type = $index->getEntityType()) && $entity_type !== $index->item_type) {
|
||||
$info[$searcher_name]['types'][] = $entity_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $info;
|
||||
@@ -80,7 +83,7 @@ function search_api_facetapi_facetapi_facet_info(array $searcher_info) {
|
||||
if (!empty($index->options['fields'])) {
|
||||
$wrapper = $index->entityWrapper();
|
||||
$bundle_key = NULL;
|
||||
if (($entity_info = entity_get_info($index->item_type)) && !empty($entity_info['bundle keys']['bundle'])) {
|
||||
if ($index->getEntityType() && ($entity_info = entity_get_info($index->getEntityType())) && !empty($entity_info['bundle keys']['bundle'])) {
|
||||
$bundle_key = $entity_info['bundle keys']['bundle'];
|
||||
}
|
||||
|
||||
@@ -144,7 +147,7 @@ function search_api_facetapi_facetapi_facet_info(array $searcher_info) {
|
||||
if ($bundle_key) {
|
||||
if ($key === $bundle_key) {
|
||||
// Set entity type this field contains bundle information for.
|
||||
$facet_info[$key]['field api bundles'][] = $index->item_type;
|
||||
$facet_info[$key]['field api bundles'][] = $index->getEntityType();
|
||||
}
|
||||
else {
|
||||
// Add "bundle" as possible dependency plugin.
|
||||
@@ -313,25 +316,49 @@ function search_api_facetapi_facet_map_callback(array $values, array $options =
|
||||
|
||||
/**
|
||||
* Creates a human-readable label for single facet filter values.
|
||||
*
|
||||
* @param array $values
|
||||
* The values for which labels should be returned.
|
||||
* @param array $options
|
||||
* An associative array containing the following information about the facet:
|
||||
* - field: Field information, as stored in the index, but with an additional
|
||||
* "key" property set to the field's internal name.
|
||||
* - index id: The machine name of the index for this facet.
|
||||
* - map callback: (optional) A callback that will be called at the beginning,
|
||||
* which allows initial mapping of filters. Only values not mapped by that
|
||||
* callback will be processed by this method.
|
||||
* - value callback: A callback used to map single values and the limits of
|
||||
* ranges. The signature is the same as for this function, but all values
|
||||
* will be single values.
|
||||
* - missing label: (optional) The label used for the "missing" facet.
|
||||
*
|
||||
* @return array
|
||||
* An array mapping raw facet values to their labels.
|
||||
*/
|
||||
function _search_api_facetapi_facet_create_label(array $values, array $options) {
|
||||
$field = $options['field'];
|
||||
$map = array();
|
||||
$n = count($values);
|
||||
|
||||
// For entities, we can simply use the entity labels.
|
||||
if (isset($field['entity_type'])) {
|
||||
$type = $field['entity_type'];
|
||||
$entities = entity_load($type, $values);
|
||||
$map = array();
|
||||
foreach ($entities as $id => $entity) {
|
||||
$label = entity_label($type, $entity);
|
||||
if ($label) {
|
||||
$map[$id] = $label;
|
||||
}
|
||||
}
|
||||
return $map;
|
||||
if (count($map) == $n) {
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
|
||||
// Then, we check whether there is an options list for the field.
|
||||
$index = search_api_index_load($options['index id']);
|
||||
$wrapper = $index->entityWrapper();
|
||||
$values = drupal_map_assoc($values);
|
||||
foreach (explode(':', $field['key']) as $part) {
|
||||
if (!isset($wrapper->$part)) {
|
||||
$wrapper = NULL;
|
||||
@@ -342,12 +369,18 @@ function _search_api_facetapi_facet_create_label(array $values, array $options)
|
||||
$wrapper = $wrapper[0];
|
||||
}
|
||||
}
|
||||
if ($wrapper && ($options = $wrapper->optionsList('view'))) {
|
||||
return $options;
|
||||
if ($wrapper && ($options_list = $wrapper->optionsList('view'))) {
|
||||
// We have no use for empty strings, as then the facet links would be
|
||||
// invisible.
|
||||
$map += array_intersect_key(array_filter($options_list, 'strlen'), $values);
|
||||
if (count($map) == $n) {
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
// As a "last resort" we try to create a label based on the field type.
|
||||
$map = array();
|
||||
foreach ($values as $value) {
|
||||
|
||||
// As a "last resort" we try to create a label based on the field type, for
|
||||
// all values that haven't got a mapping yet.
|
||||
foreach (array_diff_key($values, $map) as $value) {
|
||||
switch ($field['type']) {
|
||||
case 'boolean':
|
||||
$map[$value] = $value ? t('true') : t('false');
|
||||
|
Reference in New Issue
Block a user