query_type_geo.inc in Apache Solr Search 7
File
plugins/facetapi/query_type_geo.inc
View source
<?php
class ApacheSolrFacetapiGeo extends FacetapiQueryType implements FacetapiQueryTypeInterface {
public $center_point = '39.7391667,-104.9841667';
public $facet_options = '0.5,0.1,0.01';
public $default_radius = 100;
public static function getType() {
return 'geo';
}
public function execute($query) {
$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);
$facet_distances[] = 1;
}
$query
->addParam('pt', $this->center_point);
$query
->addParam('sfield', $this->facet['field']);
$query
->addParam('fq', '{!geofilt sfield=' . $this->facet['field'] . '}');
$query
->addParam('d', $distance);
foreach ($facet_distances as $facet_option) {
$facet_distance = $distance * $facet_option;
$query
->addParam('facet.query', '{!geofilt d=' . $facet_distance . ' key=d' . $facet_distance . '}');
}
}
public function build() {
$build = array();
if ($response = apachesolr_static_response_cache($this->adapter
->getSearcher())) {
if (isset($response->facet_counts->facet_queries)) {
foreach ($response->facet_counts->facet_queries as $value => $count) {
if ($count > 0) {
$build[$value] = array(
'#count' => $count,
);
}
}
}
}
return $build;
}
}