public function ApacheSolrFacetapiGeo::execute in Apache Solr Search 6.3
Same name and namespace in other branches
- 8 plugins/facetapi/query_type_geo.inc \ApacheSolrFacetapiGeo::execute()
- 7 plugins/facetapi/query_type_geo.inc \ApacheSolrFacetapiGeo::execute()
Adds the filter to the query object.
Parameters
DrupalSolrQueryInterface $query: An object containing the query in the backend's native API.
Overrides FacetapiQueryTypeInterface::execute
File
- plugins/
facetapi/ query_type_geo.inc, line 28
Class
- ApacheSolrFacetapiGeo
- Plugin for "apachesolr_geo" query types.
Code
public function execute($query) {
// Retrieve settings of the facet.
// We should be able to get all constants as facet options.
$settings = $this->adapter
->getFacet($this->facet)
->getSettings();
$facet_distances = explode(',', $this->facet_options);
$active_items = $this->adapter
->getActiveItems($this->facet);
if (empty($active_items)) {
$distance = $this->default_radius;
}
else {
$active_item = array_pop($active_items);
$distance = substr($active_item['value'], 1);
// Add current selected distance to have possibility to unselect it.
$facet_distances[] = 1;
}
// Search center point.
$query
->addParam('pt', $this->center_point);
// Set location field name.
$query
->addParam('sfield', $this->facet['field']);
$query
->addParam('fq', '{!geofilt sfield=' . $this->facet['field'] . '}');
// Set search radius.
$query
->addParam('d', $distance);
// Set facets.
foreach ($facet_distances as $facet_option) {
$facet_distance = $distance * $facet_option;
$query
->addParam('facet.query', '{!geofilt d=' . $facet_distance . ' key=d' . $facet_distance . '}');
}
}