Created
June 17, 2011 11:55
-
-
Save cbiggins/1031279 to your computer and use it in GitHub Desktop.
Simple geo targeted search with Sphinx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('sphinxapi.php'); | |
$sphinx = new sphinxClient; | |
$sphinx->SetServer('localhost',9312); | |
// How many k's from the target do we want to return results from? | |
// 10k's should do it. (In metres) | |
// @geodist is a magic key displaying metres from target. | |
$sphinx->SetFilterFloatRange('@geodist',0,10000); | |
// We'll base our search in Sydney CBD... | |
// $ search -i suburbs 'sydney' gives this... | |
// 3. document=188, weight=1, postcode=2000, lat=-0.591084, lon=2.639081 | |
$sphinx->SetGeoAnchor('lat', 'lon', -0.591084, 2.639081); | |
// Sort by the distance from our target | |
$sphinx->SetSortMode(SPH_SORT_EXTENDED, "@geodist ASC"); | |
// Run the query | |
$results = $sphinx->Query('', 'suburbs'); | |
// Check the results. | |
dump($results['matches']); | |
function dump($s) { | |
print '<pre>'; | |
print_r($s); | |
print '</pre>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment