Permalink
Browse files

add nearby wrapper for solr; not really a calendar thing but whatever

  • Loading branch information...
thisisaaronland committed Nov 28, 2011
1 parent 4e54c28 commit d80fc01ae06b7e5321c51fe195191ec759e744d8
Showing with 37 additions and 5 deletions.
  1. +35 −1 www/include/lib_solr.php
  2. +2 −4 www/include/lib_solr_utils.php
View
@@ -9,6 +9,7 @@
#################################################################
loadlib("http");
loadlib("solr_utils");
#################################################################
@@ -63,6 +64,39 @@ function solr_select($params, $more=array()){
#################################################################
# https://wiki.apache.org/solr/SpatialSearch#QuickStart
function solr_select_nearby($lat, $lon, $params=array(), $more=array()){
$defaults = array(
"d" => 1,
"sfield" => "location",
"sort" => "geodist() asc",
);
$more = array_merge($defaults, $more);
if (! isset($params['q'])){
$query = array(
"*" => "*",
);
$q = solr_utils_hash2query($query, " AND ");
$params['q'] = $q;
}
$params['fq'] = "{!geofilt}";
$params['pt'] = "{$lat},{$lon}";
$params['sfield'] = $more['sfield'];
$params['d'] = $more['d'];
$params['sort'] = $more['sort'];
return solr_select($params, $more);
}
#################################################################
# https://wiki.apache.org/solr/SimpleFacetParameters
# https://wiki.apache.org/solr/SolrFacetingOverview
@@ -230,7 +264,7 @@ function _solr_build_query(&$params, $stringify=0){
$v = (is_array($v)) ? $v : array($v);
foreach ($v as $_v){
$query[] = "$k=" . urlencode($_v);
$query[] = "$k=" . urlencode($_v);
}
}
@@ -8,8 +8,6 @@ function solr_utils_hash2query(&$hash, $join=null){
foreach ($hash as $k => $v){
$k = urlencode($k);
$v = (preg_match("/^raw:(.*)$/", $v, $m)) ? $m[1] : solr_utils_escape($v);
$q[] = "{$k}:{$v}";
@@ -28,8 +26,8 @@ function solr_utils_hash2query(&$hash, $join=null){
function solr_utils_escape($string){
$match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' ');
$replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ ');
$match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '?', ':', '"', ';', ' ');
$replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\?', '\\:', '\\"', '\\;', '\\ ');
$string = str_replace($match, $replace, $string);
return $string;
}

0 comments on commit d80fc01

Please sign in to comment.