GeoShapeProvided.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * geo_shape query for provided shapes.
  5. *
  6. * Query provided shape definitions
  7. *
  8. * @author BennieKrijger <benniekrijger@gmail.com>
  9. *
  10. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
  11. */
  12. class GeoShapeProvided extends AbstractGeoShape
  13. {
  14. const TYPE_ENVELOPE = 'envelope';
  15. const TYPE_MULTIPOINT = 'multipoint';
  16. const TYPE_POINT = 'point';
  17. const TYPE_MULTIPOLYGON = 'multipolygon';
  18. const TYPE_LINESTRING = 'linestring';
  19. const TYPE_POLYGON = 'polygon';
  20. /**
  21. * Type of the geo_shape.
  22. *
  23. * @var string
  24. */
  25. protected $_shapeType;
  26. /**
  27. * Coordinates making up geo_shape.
  28. *
  29. * @var array Coordinates making up geo_shape
  30. */
  31. protected $_coordinates;
  32. /**
  33. * Construct geo_shape query.
  34. *
  35. * @param string $path The path/field of the shape searched
  36. * @param array $coordinates Points making up the shape
  37. * @param string $shapeType Type of the geo_shape:
  38. * point, envelope, linestring, polygon,
  39. * multipoint or multipolygon
  40. */
  41. public function __construct($path, array $coordinates, $shapeType = self::TYPE_ENVELOPE)
  42. {
  43. $this->_path = $path;
  44. $this->_shapeType = $shapeType;
  45. $this->_coordinates = $coordinates;
  46. }
  47. /**
  48. * Converts query to array.
  49. *
  50. * @see \Elastica\Query\AbstractQuery::toArray()
  51. *
  52. * @return array
  53. */
  54. public function toArray()
  55. {
  56. return [
  57. 'geo_shape' => [
  58. $this->_path => [
  59. 'shape' => [
  60. 'type' => $this->_shapeType,
  61. 'coordinates' => $this->_coordinates,
  62. ],
  63. 'relation' => $this->_relation,
  64. ],
  65. ],
  66. ];
  67. }
  68. }