1
|
|
<?php
|
2
|
|
|
3
|
|
/*
|
4
|
|
* This file is part of the Solarium package.
|
5
|
|
*
|
6
|
|
* For the full copyright and license information, please view the COPYING
|
7
|
|
* file that was distributed with this source code.
|
8
|
|
*/
|
9
|
|
|
10
|
|
namespace Solarium\QueryType\Server\Collections\Query\Action;
|
11
|
|
|
12
|
|
use Solarium\QueryType\Server\Collections\Query\Query as CollectionsQuery;
|
13
|
|
use Solarium\QueryType\Server\Collections\Result\CreateResult;
|
14
|
|
use Solarium\QueryType\Server\Query\Action\AsyncActionInterface;
|
15
|
|
|
16
|
|
/**
|
17
|
|
* Class Create.
|
18
|
|
*
|
19
|
|
* @see https://lucene.apache.org/solr/guide/collection-management.html#create
|
20
|
|
*/
|
21
|
|
class Create extends AbstractCDRAction
|
22
|
|
{
|
23
|
|
/**
|
24
|
|
* Returns the action type of the Collections API action.
|
25
|
|
*
|
26
|
|
* @return string
|
27
|
|
*/
|
28
|
12
|
public function getType(): string
|
29
|
|
{
|
30
|
12
|
return CollectionsQuery::ACTION_CREATE;
|
31
|
|
}
|
32
|
|
|
33
|
|
/**
|
34
|
|
* The router name that will be used. The router defines how documents will be distributed among the shards.
|
35
|
|
* Possible values are implicit or compositeId, which is the default.
|
36
|
|
*
|
37
|
|
* @param string $routerName
|
38
|
|
*
|
39
|
|
* @return self $this
|
40
|
|
*/
|
41
|
12
|
public function setRouterName(string $routerName): self
|
42
|
|
{
|
43
|
12
|
$this->setOption('router.name', $routerName);
|
44
|
|
|
45
|
12
|
return $this;
|
46
|
|
}
|
47
|
|
|
48
|
|
/**
|
49
|
|
* Returns the router name.
|
50
|
|
*
|
51
|
|
* @return string|null
|
52
|
|
*/
|
53
|
0
|
public function getRouterName(): ?string
|
54
|
|
{
|
55
|
0
|
return $this->getOption('router.name');
|
56
|
|
}
|
57
|
|
|
58
|
|
/**
|
59
|
|
* The number of shards to be created as part of the collection.
|
60
|
|
* This is a required parameter when the router.name is compositeId.
|
61
|
|
*
|
62
|
|
* @param int $numShards
|
63
|
|
*
|
64
|
|
* @return self $this
|
65
|
|
*/
|
66
|
12
|
public function setNumShards(int $numShards): self
|
67
|
|
{
|
68
|
12
|
$this->setOption('numShards', $numShards);
|
69
|
|
|
70
|
12
|
return $this;
|
71
|
|
}
|
72
|
|
|
73
|
|
/**
|
74
|
|
* Returns the number of shards.
|
75
|
|
*
|
76
|
|
* @return int|null
|
77
|
|
*/
|
78
|
0
|
public function getNumShards(): ?int
|
79
|
|
{
|
80
|
0
|
return $this->getOption('numShards');
|
81
|
|
}
|
82
|
|
|
83
|
|
/**
|
84
|
|
* A comma separated list of shard names, e.g., shard-x,shard-y,shard-z.
|
85
|
|
* This is a required parameter when the router.name is implicit.
|
86
|
|
*
|
87
|
|
* @param string $shards
|
88
|
|
*
|
89
|
|
* @return self $this
|
90
|
|
*/
|
91
|
12
|
public function setShards(string $shards): self
|
92
|
|
{
|
93
|
12
|
$this->setOption('shards', $shards);
|
94
|
|
|
95
|
12
|
return $this;
|
96
|
|
}
|
97
|
|
|
98
|
|
/**
|
99
|
|
* Returns the shards.
|
100
|
|
*
|
101
|
|
* @return string|null
|
102
|
|
*/
|
103
|
0
|
public function getShards(): ?string
|
104
|
|
{
|
105
|
0
|
return $this->getOption('shards');
|
106
|
|
}
|
107
|
|
|
108
|
|
/**
|
109
|
|
* The number of replicas to be created for each shard. The default is 1.
|
110
|
|
*
|
111
|
|
* @param int $replicationFactor
|
112
|
|
*
|
113
|
|
* @return self Provides fluent interface
|
114
|
|
*/
|
115
|
12
|
public function setReplicationFactor(int $replicationFactor): self
|
116
|
|
{
|
117
|
12
|
$this->setOption('replicationFactor', $replicationFactor);
|
118
|
|
|
119
|
12
|
return $this;
|
120
|
|
}
|
121
|
|
|
122
|
|
/**
|
123
|
|
* The number of NRT (Near-Real-Time) replicas to create for this collection.
|
124
|
|
*
|
125
|
|
* @param int $nrtReplicas
|
126
|
|
*
|
127
|
|
* @return self Provides fluent interface
|
128
|
|
*/
|
129
|
12
|
public function setNrtReplicas(int $nrtReplicas): self
|
130
|
|
{
|
131
|
12
|
$this->setOption('nrtReplicas', $nrtReplicas);
|
132
|
|
|
133
|
12
|
return $this;
|
134
|
|
}
|
135
|
|
|
136
|
|
/**
|
137
|
|
* The number of TLOG replicas to create for this collection.
|
138
|
|
*
|
139
|
|
* @param int $tlogReplicas
|
140
|
|
*
|
141
|
|
* @return self Provides fluent interface
|
142
|
|
*/
|
143
|
12
|
public function setTlogReplicas(int $tlogReplicas): self
|
144
|
|
{
|
145
|
12
|
$this->setOption('tlogReplicas', $tlogReplicas);
|
146
|
|
|
147
|
12
|
return $this;
|
148
|
|
}
|
149
|
|
|
150
|
|
/**
|
151
|
|
* The number of PULL replicas to create for this collection.
|
152
|
|
*
|
153
|
|
* @param int $pullReplicas
|
154
|
|
*
|
155
|
|
* @return self Provides fluent interface
|
156
|
|
*/
|
157
|
12
|
public function setPullReplicas(int $pullReplicas): self
|
158
|
|
{
|
159
|
12
|
$this->setOption('pullReplicas', $pullReplicas);
|
160
|
|
|
161
|
12
|
return $this;
|
162
|
|
}
|
163
|
|
|
164
|
|
/**
|
165
|
|
* When creating collections, the shards and/or replicas are spread across all available (i.e., live) nodes, and
|
166
|
|
* two replicas of the same shard will never be on the same node.
|
167
|
|
*
|
168
|
|
* @param int $maxShardsPerNode
|
169
|
|
*
|
170
|
|
* @return self Provides fluent interface
|
171
|
|
*/
|
172
|
12
|
public function setMaxShardsPerNode(int $maxShardsPerNode): self
|
173
|
|
{
|
174
|
12
|
$this->setOption('maxShardsPerNode', $maxShardsPerNode);
|
175
|
|
|
176
|
12
|
return $this;
|
177
|
|
}
|
178
|
|
|
179
|
|
/**
|
180
|
|
* Allows defining the nodes to spread the new collection across. The format is a comma-separated list of
|
181
|
|
* node_names, such as localhost:8983_solr,localhost:8984_solr,localhost:8985_solr.
|
182
|
|
*
|
183
|
|
* @param string $createNodeSet
|
184
|
|
*
|
185
|
|
* @return self Provides fluent interface
|
186
|
|
*/
|
187
|
12
|
public function setCreateNodeSet(string $createNodeSet): self
|
188
|
|
{
|
189
|
12
|
$this->setOption('createNodeSet', $createNodeSet);
|
190
|
|
|
191
|
12
|
return $this;
|
192
|
|
}
|
193
|
|
|
194
|
|
/**
|
195
|
|
* Controls wether or not the shard-replicas created for this collection will be assigned to the nodes specified by
|
196
|
|
* the createNodeSet in a sequential manner, or if the list of nodes should be shuffled prior to creating
|
197
|
|
* individual replicas.
|
198
|
|
*
|
199
|
|
* @param bool $shuffle
|
200
|
|
*
|
201
|
|
* @return self Provides fluent interface
|
202
|
|
*/
|
203
|
12
|
public function setCreateNodeSetShuffle(bool $shuffle): self
|
204
|
|
{
|
205
|
12
|
$this->setOption('createNodeSet.shuffle', $shuffle);
|
206
|
|
|
207
|
12
|
return $this;
|
208
|
|
}
|
209
|
|
|
210
|
|
/**
|
211
|
|
* Set the collection config name.
|
212
|
|
*
|
213
|
|
* @param string $configName
|
214
|
|
*
|
215
|
|
* @return self Provides fluent interface
|
216
|
|
*/
|
217
|
12
|
public function setCollectionConfigName(string $configName): self
|
218
|
|
{
|
219
|
12
|
$this->setOption('collection.configName', $configName);
|
220
|
|
|
221
|
12
|
return $this;
|
222
|
|
}
|
223
|
|
|
224
|
|
/**
|
225
|
|
* Get the collection config name.
|
226
|
|
*
|
227
|
|
* @return string|null
|
228
|
|
*/
|
229
|
0
|
public function getCollectionConfigName(): ?string
|
230
|
|
{
|
231
|
0
|
return $this->getOption('collection.configName');
|
232
|
|
}
|
233
|
|
|
234
|
|
/**
|
235
|
|
* If this parameter is specified, the router will look at the value of the field in an input document to compute
|
236
|
|
* the hash and identify a shard instead of looking at the uniqueKey field. If the field specified is null in the
|
237
|
|
* document, the document will be rejected.
|
238
|
|
*
|
239
|
|
* @param string $routerField
|
240
|
|
*
|
241
|
|
* @return self Provides fluent interface
|
242
|
|
*/
|
243
|
12
|
public function setRouterField(string $routerField): self
|
244
|
|
{
|
245
|
12
|
$this->setOption('router.field', $routerField);
|
246
|
|
|
247
|
12
|
return $this;
|
248
|
|
}
|
249
|
|
|
250
|
|
/**
|
251
|
|
* Set core property name to value.
|
252
|
|
*
|
253
|
|
* @param string $name
|
254
|
|
* @param string $value
|
255
|
|
*
|
256
|
|
* @return self Provides fluent interface
|
257
|
|
*/
|
258
|
12
|
public function setProperty(string $name, string $value): self
|
259
|
|
{
|
260
|
12
|
$this->setOption('property.'.$name, $value);
|
261
|
|
|
262
|
12
|
return $this;
|
263
|
|
}
|
264
|
|
|
265
|
|
/**
|
266
|
|
* Get a previously added property.
|
267
|
|
*
|
268
|
|
* @param string $name property name
|
269
|
|
*
|
270
|
|
* @return string|null
|
271
|
|
*/
|
272
|
0
|
public function getProperty(string $name): ?string
|
273
|
|
{
|
274
|
0
|
return $this->getOption('property.'.$name);
|
275
|
|
}
|
276
|
|
|
277
|
|
/**
|
278
|
|
* When set to true, enables automatic addition of replicas when the number of active replicas falls below the
|
279
|
|
* value set for replicationFactor. This may occur if a replica goes down, for example.
|
280
|
|
* The default is false, which means new replicas will not be added.
|
281
|
|
*
|
282
|
|
* @param bool $autoAddReplicas
|
283
|
|
*
|
284
|
|
* @return self Provides fluent interface
|
285
|
|
*/
|
286
|
12
|
public function setAutoAddReplicas(bool $autoAddReplicas): self
|
287
|
|
{
|
288
|
12
|
$this->setOption('autoAddReplicas', $autoAddReplicas);
|
289
|
|
|
290
|
12
|
return $this;
|
291
|
|
}
|
292
|
|
|
293
|
|
/**
|
294
|
|
* Request ID to track this action which will be processed asynchronously.
|
295
|
|
*
|
296
|
|
* @param string $id
|
297
|
|
*
|
298
|
|
* @return self Provides fluent interface
|
299
|
|
*/
|
300
|
12
|
public function setAsync(string $id): AsyncActionInterface
|
301
|
|
{
|
302
|
12
|
$this->setOption('async', $id);
|
303
|
|
|
304
|
12
|
return $this;
|
305
|
|
}
|
306
|
|
|
307
|
|
/**
|
308
|
|
* Replica placement rules.
|
309
|
|
*
|
310
|
|
* @param string $rule
|
311
|
|
*
|
312
|
|
* @return self Provides fluent interface
|
313
|
|
*/
|
314
|
12
|
public function setRule(string $rule): self
|
315
|
|
{
|
316
|
12
|
$this->setOption('rule', $rule);
|
317
|
|
|
318
|
12
|
return $this;
|
319
|
|
}
|
320
|
|
|
321
|
|
/**
|
322
|
|
* Details of the snitch provider.
|
323
|
|
*
|
324
|
|
* @param string $snitch
|
325
|
|
*
|
326
|
|
* @return self Provides fluent interface
|
327
|
|
*/
|
328
|
12
|
public function setSnitch(string $snitch): self
|
329
|
|
{
|
330
|
12
|
$this->setOption('snitch', $snitch);
|
331
|
|
|
332
|
12
|
return $this;
|
333
|
|
}
|
334
|
|
|
335
|
|
/**
|
336
|
|
* Name of the collection-level policy.
|
337
|
|
*
|
338
|
|
* @param string $policy
|
339
|
|
*
|
340
|
|
* @return self Provides fluent interface
|
341
|
|
*/
|
342
|
12
|
public function setPolicy(string $policy): self
|
343
|
|
{
|
344
|
12
|
$this->setOption('policy', $policy);
|
345
|
|
|
346
|
12
|
return $this;
|
347
|
|
}
|
348
|
|
|
349
|
|
/**
|
350
|
|
* If true, the request will complete only when all affected replicas become active. The default is false, which
|
351
|
|
* means that the API will return the status of the single action, which may be before the new replica is online
|
352
|
|
* and active.
|
353
|
|
*
|
354
|
|
* @param bool $waitForFinalState
|
355
|
|
*
|
356
|
|
* @return self Provides fluent interface
|
357
|
|
*/
|
358
|
12
|
public function setWaitForFinalState(bool $waitForFinalState): self
|
359
|
|
{
|
360
|
12
|
$this->setOption('waitForFinalState', $waitForFinalState);
|
361
|
|
|
362
|
12
|
return $this;
|
363
|
|
}
|
364
|
|
|
365
|
|
/**
|
366
|
|
* The name of the collection with which all replicas of this collection must be co-located.
|
367
|
|
* The collection must already exist and must have a single shard named shard1.
|
368
|
|
*
|
369
|
|
* @param string $withCollection
|
370
|
|
*
|
371
|
|
* @return self Provides fluent interface
|
372
|
|
*/
|
373
|
12
|
public function setWithCollection(string $withCollection): self
|
374
|
|
{
|
375
|
12
|
$this->setOption('withCollection', $withCollection);
|
376
|
|
|
377
|
12
|
return $this;
|
378
|
|
}
|
379
|
|
|
380
|
|
/**
|
381
|
|
* Returns the namespace and class of the result class for the action.
|
382
|
|
*
|
383
|
|
* @return string
|
384
|
|
*/
|
385
|
0
|
public function getResultClass(): string
|
386
|
|
{
|
387
|
0
|
return CreateResult::class;
|
388
|
|
}
|
389
|
|
}
|