GeoDistance.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * Geo distance query.
  5. *
  6. * @author Nicolas Ruflin <spam@ruflin.com>
  7. *
  8. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
  9. */
  10. class GeoDistance extends AbstractGeoDistance
  11. {
  12. const DISTANCE_TYPE_ARC = 'arc';
  13. const DISTANCE_TYPE_PLANE = 'plane';
  14. /**
  15. * Create GeoDistance object.
  16. *
  17. * @param string $key Key
  18. * @param array|string $location Location as array or geohash: array('lat' => 48.86, 'lon' => 2.35) OR 'drm3btev3e86'
  19. * @param string $distance Distance
  20. *
  21. * @throws \Elastica\Exception\InvalidException
  22. */
  23. public function __construct($key, $location, $distance)
  24. {
  25. parent::__construct($key, $location);
  26. $this->setDistance($distance);
  27. }
  28. /**
  29. * @param string $distance
  30. *
  31. * @return $this
  32. */
  33. public function setDistance($distance)
  34. {
  35. $this->setParam('distance', $distance);
  36. return $this;
  37. }
  38. /**
  39. * See DISTANCE_TYPE_* constants.
  40. *
  41. * @param string $distanceType, default arc
  42. *
  43. * @return $this
  44. */
  45. public function setDistanceType($distanceType)
  46. {
  47. $this->setParam('distance_type', $distanceType);
  48. return $this;
  49. }
  50. }