GeoPolygon.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * Geo polygon query.
  5. *
  6. * @author Michael Maclean <mgdm@php.net>
  7. *
  8. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html
  9. */
  10. class GeoPolygon extends AbstractQuery
  11. {
  12. /**
  13. * Key.
  14. *
  15. * @var string Key
  16. */
  17. protected $_key;
  18. /**
  19. * Points making up polygon.
  20. *
  21. * @var array Points making up polygon
  22. */
  23. protected $_points;
  24. /**
  25. * Construct polygon query.
  26. *
  27. * @param string $key Key
  28. * @param array $points Points making up polygon
  29. */
  30. public function __construct($key, array $points)
  31. {
  32. $this->_key = $key;
  33. $this->_points = $points;
  34. }
  35. /**
  36. * Converts query to array.
  37. *
  38. * @see \Elastica\Query\AbstractQuery::toArray()
  39. *
  40. * @return array
  41. */
  42. public function toArray()
  43. {
  44. return [
  45. 'geo_polygon' => [
  46. $this->_key => [
  47. 'points' => $this->_points,
  48. ],
  49. ],
  50. ];
  51. }
  52. /**
  53. * {@inheritdoc}
  54. *
  55. * @return int
  56. */
  57. public function count()
  58. {
  59. return count($this->_key);
  60. }
  61. }