GeoShapePreIndexed.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * geo_shape query for pre-indexed shapes.
  5. *
  6. * Query pre-indexed shape definitions
  7. *
  8. * @author Bennie Krijger <benniekrijger@gmail.com>
  9. *
  10. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
  11. */
  12. class GeoShapePreIndexed extends AbstractGeoShape
  13. {
  14. /**
  15. * elasticsearch id of the pre-indexed shape.
  16. *
  17. * @var string
  18. */
  19. protected $_indexedId;
  20. /**
  21. * elasticsearch type of the pre-indexed shape.
  22. *
  23. * @var string
  24. */
  25. protected $_indexedType;
  26. /**
  27. * elasticsearch index of the pre-indexed shape.
  28. *
  29. * @var string
  30. */
  31. protected $_indexedIndex;
  32. /**
  33. * elasticsearch path/field name of the pre-indexed shape.
  34. *
  35. * @var string
  36. */
  37. protected $_indexedPath;
  38. /**
  39. * Construct geo_shape query with a pre-indexed shape.
  40. *
  41. * @param string $path The path/field of the shape searched
  42. * @param string $indexedId Id of the pre-indexed shape
  43. * @param string $indexedType Type of the pre-indexed shape
  44. * @param string $indexedIndex Index of the pre-indexed shape
  45. * @param string $indexedPath Path of the pre-indexed shape
  46. */
  47. public function __construct($path, $indexedId, $indexedType, $indexedIndex, $indexedPath)
  48. {
  49. $this->_path = $path;
  50. $this->_indexedId = $indexedId;
  51. $this->_indexedType = $indexedType;
  52. $this->_indexedIndex = $indexedIndex;
  53. $this->_indexedPath = $indexedPath;
  54. }
  55. /**
  56. * Converts query to array.
  57. *
  58. * @see \Elastica\Query\AbstractQuery::toArray()
  59. *
  60. * @return array
  61. */
  62. public function toArray()
  63. {
  64. return [
  65. 'geo_shape' => [
  66. $this->_path => [
  67. 'indexed_shape' => [
  68. 'id' => $this->_indexedId,
  69. 'type' => $this->_indexedType,
  70. 'index' => $this->_indexedIndex,
  71. 'path' => $this->_indexedPath,
  72. ],
  73. 'relation' => $this->_relation,
  74. ],
  75. ],
  76. ];
  77. }
  78. }