DateHistogram.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Elastica\Aggregation;
  3. /**
  4. * Class DateHistogram.
  5. *
  6. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
  7. */
  8. class DateHistogram extends Histogram
  9. {
  10. /**
  11. * Set time_zone option.
  12. *
  13. * @param string
  14. *
  15. * @return $this
  16. */
  17. public function setTimezone($timezone)
  18. {
  19. return $this->setParam('time_zone', $timezone);
  20. }
  21. /**
  22. * Adjust for granularity of date data.
  23. *
  24. * @param int $factor set to 1000 if date is stored in seconds rather than milliseconds
  25. *
  26. * @return $this
  27. */
  28. public function setFactor($factor)
  29. {
  30. return $this->setParam('factor', $factor);
  31. }
  32. /**
  33. * Set offset option.
  34. *
  35. * @param string
  36. *
  37. * @return $this
  38. */
  39. public function setOffset($offset)
  40. {
  41. return $this->setParam('offset', $offset);
  42. }
  43. /**
  44. * Set the format for returned bucket key_as_string values.
  45. *
  46. * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
  47. *
  48. * @param string $format see link for formatting options
  49. *
  50. * @return $this
  51. */
  52. public function setFormat($format)
  53. {
  54. return $this->setParam('format', $format);
  55. }
  56. /**
  57. * Set extended bounds option.
  58. *
  59. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html#search-aggregations-bucket-histogram-aggregation-extended-bounds
  60. *
  61. * @param string $min see link for formatting options
  62. * @param string $max see link for formatting options
  63. *
  64. * @return $this
  65. */
  66. public function setExtendedBounds($min = '', $max = '')
  67. {
  68. $bounds = [];
  69. $bounds['min'] = $min;
  70. $bounds['max'] = $max;
  71. // switch if min is higher then max
  72. if (strtotime($min) > strtotime($max)) {
  73. $bounds['min'] = $max;
  74. $bounds['max'] = $min;
  75. }
  76. return $this->setParam('extended_bounds', $bounds);
  77. }
  78. }