DateIndexName.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Elastica\Processor;
  3. /**
  4. * Elastica DateIndexName Processor.
  5. *
  6. * @author Federico Panini <fpanini@gmail.com>
  7. *
  8. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/date-index-name-processor.html
  9. */
  10. class DateIndexName extends AbstractProcessor
  11. {
  12. /**
  13. * DateIndexName constructor.
  14. *
  15. * @param string $field
  16. * @param string $dateRounding
  17. */
  18. public function __construct(string $field, string $dateRounding)
  19. {
  20. $this->setField($field);
  21. $this->setDateRounding($dateRounding);
  22. }
  23. /**
  24. * Set field.
  25. *
  26. * @param string $field
  27. *
  28. * @return $this
  29. */
  30. public function setField(string $field)
  31. {
  32. return $this->setParam('field', $field);
  33. }
  34. /**
  35. * Set date_rounding. Valid values are: y (year), M (month), w (week), d (day), h (hour), m (minute) and s (second).
  36. *
  37. * @param string $dateRounding
  38. *
  39. * @return $this
  40. */
  41. public function setDateRounding(string $dateRounding)
  42. {
  43. return $this->setParam('date_rounding', $dateRounding);
  44. }
  45. /**
  46. * Set field formats. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N.
  47. *
  48. * @param array $formats
  49. *
  50. * @return $this
  51. */
  52. public function setDateFormats(array $formats)
  53. {
  54. return $this->setParam('date_formats', $formats);
  55. }
  56. /**
  57. * Set index_prefix_name.
  58. *
  59. * @param string $indexPrefixName
  60. *
  61. * @return $this
  62. */
  63. public function setIndexNamePrefix(string $indexPrefixName)
  64. {
  65. return $this->setParam('index_name_prefix', $indexPrefixName);
  66. }
  67. /**
  68. * Set format to be used when printing parsed date. An valid Joda pattern is expected here. Default yyyy-MM-dd.
  69. *
  70. * @param string $indexNameFormat
  71. *
  72. * @return $this
  73. */
  74. public function setIndexNameFormat(string $indexNameFormat)
  75. {
  76. return $this->setParam('index_name_format', $indexNameFormat);
  77. }
  78. /**
  79. * Set the timezone use when parsing the date. Default UTC.
  80. *
  81. * @param string $timezone
  82. *
  83. * @return $this
  84. */
  85. public function setTimezone(string $timezone)
  86. {
  87. return $this->setParam('timezone', $timezone);
  88. }
  89. /**
  90. * Set the locale to use when parsing the date.
  91. *
  92. * @param string $locale
  93. *
  94. * @return $this
  95. */
  96. public function setLocale(string $locale)
  97. {
  98. return $this->setParam('locale', $locale);
  99. }
  100. }