GeohashGrid.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Elastica\Aggregation;
  3. /**
  4. * Class GeohashGrid.
  5. *
  6. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html
  7. */
  8. class GeohashGrid extends AbstractAggregation
  9. {
  10. /**
  11. * @param string $name the name of this aggregation
  12. * @param string $field the field on which to perform this aggregation
  13. */
  14. public function __construct($name, $field)
  15. {
  16. parent::__construct($name);
  17. $this->setField($field);
  18. }
  19. /**
  20. * Set the field for this aggregation.
  21. *
  22. * @param string $field the name of the document field on which to perform this aggregation
  23. *
  24. * @return $this
  25. */
  26. public function setField($field)
  27. {
  28. return $this->setParam('field', $field);
  29. }
  30. /**
  31. * Set the precision for this aggregation.
  32. *
  33. * @param int $precision an integer between 1 and 12, inclusive. Defaults to 5.
  34. *
  35. * @return $this
  36. */
  37. public function setPrecision($precision)
  38. {
  39. return $this->setParam('precision', $precision);
  40. }
  41. /**
  42. * Set the maximum number of buckets to return.
  43. *
  44. * @param int $size defaults to 10,000
  45. *
  46. * @return $this
  47. */
  48. public function setSize($size)
  49. {
  50. return $this->setParam('size', $size);
  51. }
  52. /**
  53. * Set the number of results returned from each shard.
  54. *
  55. * @param int $shardSize
  56. *
  57. * @return $this
  58. */
  59. public function setShardSize($shardSize)
  60. {
  61. return $this->setParam('shard_size', $shardSize);
  62. }
  63. }