1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\ElasticsearchBundle\Document; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Annotation as ES; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* This trait provides support for main Elasticsearch meta fields. |
18
|
|
|
*/ |
19
|
|
|
trait DocumentTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
* |
24
|
|
|
* @ES\MetaField(name="_id") |
25
|
|
|
*/ |
26
|
|
|
public $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
* |
31
|
|
|
* @ES\MetaField(name="_score") |
32
|
|
|
*/ |
33
|
|
|
public $score; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
* |
38
|
|
|
* @ES\MetaField(name="_parent") |
39
|
|
|
*/ |
40
|
|
|
public $parent; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
* |
45
|
|
|
* @ES\MetaField(name="_ttl") |
46
|
|
|
*/ |
47
|
|
|
public $ttl; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* When document is cloned id is set to null. |
51
|
|
|
*/ |
52
|
|
|
public function __clone() |
53
|
|
|
{ |
54
|
|
|
$this->setId(null); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Sets document unique id. |
59
|
|
|
* |
60
|
|
|
* @param string $documentId |
61
|
|
|
* |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
|
public function setId($documentId) |
65
|
|
|
{ |
66
|
|
|
$this->id = $documentId; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns document id. |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getId() |
77
|
|
|
{ |
78
|
|
|
return $this->id; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sets document score. |
83
|
|
|
* |
84
|
|
|
* @param string $documentScore |
85
|
|
|
* |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
|
|
public function setScore($documentScore) |
89
|
|
|
{ |
90
|
|
|
$this->score = $documentScore; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Gets document score. |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getScore() |
101
|
|
|
{ |
102
|
|
|
return $this->score; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Sets parent document id. |
107
|
|
|
* |
108
|
|
|
* @param string $parent |
109
|
|
|
* |
110
|
|
|
* @return $this |
111
|
|
|
*/ |
112
|
|
|
public function setParent($parent) |
113
|
|
|
{ |
114
|
|
|
$this->parent = $parent; |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Returns parent document id. |
121
|
|
|
* |
122
|
|
|
* @return null|string |
123
|
|
|
*/ |
124
|
|
|
public function getParent() |
125
|
|
|
{ |
126
|
|
|
return $this->parent; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Checks if document has a parent. |
131
|
|
|
* |
132
|
|
|
* @return bool |
133
|
|
|
*/ |
134
|
|
|
public function hasParent() |
135
|
|
|
{ |
136
|
|
|
return $this->parent !== null; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Sets time to live timestamp. |
141
|
|
|
* |
142
|
|
|
* @param string $ttl |
143
|
|
|
* |
144
|
|
|
* @return $this |
145
|
|
|
*/ |
146
|
|
|
public function setTtl($ttl) |
147
|
|
|
{ |
148
|
|
|
$this->ttl = $ttl; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Returns time to live value. |
155
|
|
|
* |
156
|
|
|
* @return int |
157
|
|
|
*/ |
158
|
|
|
public function getTtl() |
159
|
|
|
{ |
160
|
|
|
return $this->ttl; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|