5 require_once(CONST_BasePath.'/lib/lib.php');
9 * Collects search constraints that are independent of the
10 * actual interpretation of the search query.
12 * The search context is shared between all SearchDescriptions. This
13 * object mainly serves as context provider for the database queries.
14 * Therefore most data is directly cached as SQL statements.
18 private $fNearRadius = false;
24 public function hasNearPoint()
26 return $this->fNearRadius !== false;
29 public function nearRadius()
31 return $this->fNearRadius;
34 public function setNearPoint($fLat, $fLon, $fRadius = 0.1)
36 $this->fNearRadius = $fRadius;
37 $this->sqlNear = 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)';
41 * Extract a coordinate point from a query string.
43 * @param string $sQuery Query to scan.
45 * @return The remaining query string.
47 public function setNearPointFromQuery($sQuery)
49 $aResult = parseLatLon($sQuery);
51 if ($aResult !== false
52 && $aResult[1] <= 90.1
53 && $aResult[1] >= -90.1
54 && $aResult[2] <= 180.1
55 && $aResult[2] >= -180.1
57 $this->setNearPoint($aResult[1], $aResult[2]);
58 $sQuery = trim(str_replace($aResult[0], ' ', $sQuery));
64 public function distanceSQL($sObj)
66 return 'ST_Distance('.$this->sqlNear.", $sObj)";
69 public function withinSQL($sObj)
71 return sprintf('ST_DWithin(%s, %s, %F)', $sObj, $this->sqlNear, $this->fNearRadius);