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