- $sSQL .= ' AND ST_DWithin('.$sPointSQL.', geometry, reverse_place_diameter('.$iRankSearch.'::smallint))';
- $sSQL .= ' ORDER BY distance ASC,';
- $sSQL .= ' rank_address DESC';
- $sSQL .= ' limit 500) as a';
- $sSQL .= ' WHERE ST_CONTAINS((SELECT geometry FROM placex WHERE place_id = '.$iPlaceID.'), geometry )';
+ $sSQL .= ' AND ST_Buffer(geometry, reverse_place_diameter(rank_search)) && '.$sPointSQL;
+ $sSQL .= ' ORDER BY rank_search DESC, distance ASC';
+ $sSQL .= ' limit 100) as a';
+ $sSQL .= ' WHERE ST_Contains((SELECT geometry FROM placex WHERE place_id = '.$iPlaceID.'), geometry )';