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
|
|
|
* Sets document unique id. |
51
|
|
|
* |
52
|
|
|
* @param string $documentId |
53
|
|
|
* |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function setId($documentId) |
57
|
|
|
{ |
58
|
|
|
$this->id = $documentId; |
59
|
|
|
|
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns document id. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getId() |
69
|
|
|
{ |
70
|
|
|
return $this->id; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets document score. |
75
|
|
|
* |
76
|
|
|
* @param string $documentScore |
77
|
|
|
* |
78
|
|
|
* @return $this |
79
|
|
|
*/ |
80
|
|
|
public function setScore($documentScore) |
81
|
|
|
{ |
82
|
|
|
$this->score = $documentScore; |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Gets document score. |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getScore() |
93
|
|
|
{ |
94
|
|
|
return $this->score; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Sets parent document id. |
99
|
|
|
* |
100
|
|
|
* @param string $parent |
101
|
|
|
* |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
|
|
public function setParent($parent) |
105
|
|
|
{ |
106
|
|
|
$this->parent = $parent; |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns parent document id. |
113
|
|
|
* |
114
|
|
|
* @return null|string |
115
|
|
|
*/ |
116
|
|
|
public function getParent() |
117
|
|
|
{ |
118
|
|
|
return $this->parent; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Checks if document has a parent. |
123
|
|
|
* |
124
|
|
|
* @return bool |
125
|
|
|
*/ |
126
|
|
|
public function hasParent() |
127
|
|
|
{ |
128
|
|
|
return $this->parent !== null; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Sets time to live timestamp. |
133
|
|
|
* |
134
|
|
|
* @param string $ttl |
135
|
|
|
* |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
|
|
public function setTtl($ttl) |
139
|
|
|
{ |
140
|
|
|
$this->ttl = $ttl; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Returns time to live value. |
147
|
|
|
* |
148
|
|
|
* @return int |
149
|
|
|
*/ |
150
|
|
|
public function getTtl() |
151
|
|
|
{ |
152
|
|
|
return $this->ttl; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|