Sphinx\SphinxClient::setGeoAnchor PHP Method

setGeoAnchor() public method

Set up anchor point for geosphere distance calculations. Required to use @geodist in filters and sorting
public setGeoAnchor ( string $attrlat, string $attrlong, float $lat, float $long ) : SphinxClient
$attrlat string latitude attribute name
$attrlong string longitude attribute name
$lat float anchor point latitude (in radians)
$long float anchor point longitude (in radians)
return SphinxClient
    public function setGeoAnchor($attrlat, $attrlong, $lat, $long)
    {
        if (!is_string($attrlat)) {
            throw new \InvalidArgumentException('Latitude attribute name must be a string.');
        }
        if (!is_string($attrlong)) {
            throw new \InvalidArgumentException('Longitude attribute name must be a string.');
        }
        if (!is_numeric($lat)) {
            throw new \InvalidArgumentException('Latitude must be a float.');
        }
        if (!is_numeric($long)) {
            throw new \InvalidArgumentException('Longitude must be a float.');
        }
        $this->anchor = array('attrlat' => $attrlat, 'attrlong' => $attrlong, 'lat' => $lat, 'long' => $long);
        return $this;
    }

Usage Example

Example #1
0
 public function testGeoAnchor()
 {
     $sphinx = new SphinxClient();
     $sphinx->setGeoAnchor('lat', 'long', 0.4, 0.4)->setMatchMode(SphinxClient::SPH_MATCH_EXTENDED)->setSortMode(SphinxClient::SPH_SORT_EXTENDED, '@geodist desc')->setFilterFloatRange('@geodist', 0, 1934127);
     $results = $sphinx->query('a');
     $this->assertEquals(array_keys($results['matches']), array('1', '3', '4'));
 }
All Usage Examples Of Sphinx\SphinxClient::setGeoAnchor