1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Trait SolrIndexTrait|Firesphere\SolrSearch\Traits\SolrIndexTrait Used to extract methods from the |
4
|
|
|
* {@link \Firesphere\SolrSearch\Tasks\SolrIndexTask} to make the code more readable |
5
|
|
|
* |
6
|
|
|
* @package Firesphere\SolrSearch\Traits |
7
|
|
|
* @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo |
8
|
|
|
* @copyright Copyright (c) 2018 - now() Firesphere & Sheepy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Firesphere\SolrSearch\Traits; |
12
|
|
|
|
13
|
|
|
use Firesphere\SolrSearch\Indexes\BaseIndex; |
14
|
|
|
use Firesphere\SolrSearch\Services\SolrCoreService; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Trait SolrIndexTrait |
18
|
|
|
* Getters and Setters for the SolrIndexTask |
19
|
|
|
* |
20
|
|
|
* @package Firesphere\SolrSearch\Traits |
21
|
|
|
*/ |
22
|
|
|
trait SolrIndexTrait |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Debug mode enabled, default false |
26
|
|
|
* |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
protected $debug = false; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Singleton of {@link SolrCoreService} |
33
|
|
|
* |
34
|
|
|
* @var SolrCoreService |
35
|
|
|
*/ |
36
|
|
|
protected $service; |
37
|
|
|
/** |
38
|
|
|
* @var BaseIndex Current core being indexed |
39
|
|
|
*/ |
40
|
|
|
protected $index; |
41
|
|
|
/** |
42
|
|
|
* @var int Number of CPU cores available |
43
|
|
|
*/ |
44
|
|
|
protected $cores = 1; |
45
|
|
|
/** |
46
|
|
|
* Default batch length |
47
|
|
|
* |
48
|
|
|
* @var int |
49
|
|
|
*/ |
50
|
|
|
protected $batchLength = 500; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set the {@link SolrCoreService} |
54
|
|
|
* |
55
|
|
|
* @param SolrCoreService $service |
56
|
|
|
* @return self |
57
|
|
|
*/ |
58
|
16 |
|
public function setService(SolrCoreService $service): self |
59
|
|
|
{ |
60
|
16 |
|
$this->service = $service; |
61
|
|
|
|
62
|
16 |
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Set the debug mode |
67
|
|
|
* |
68
|
|
|
* @param bool $debug |
69
|
|
|
* @return self |
70
|
|
|
*/ |
71
|
16 |
|
public function setDebug(bool $debug): self |
72
|
|
|
{ |
73
|
|
|
// Make the debug a configurable, forcing it to always be false from config |
74
|
16 |
|
if (SolrCoreService::config()->get('debug') === false) { |
75
|
1 |
|
$debug = false; |
76
|
|
|
} |
77
|
|
|
|
78
|
16 |
|
$this->debug = $debug; |
79
|
|
|
|
80
|
16 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Is this Index in debug mode |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
1 |
|
public function isDebug(): bool |
88
|
|
|
{ |
89
|
1 |
|
return $this->debug; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get the Index class. |
94
|
|
|
* |
95
|
|
|
* @return BaseIndex |
96
|
|
|
*/ |
97
|
14 |
|
public function getIndex(): BaseIndex |
98
|
|
|
{ |
99
|
14 |
|
return $this->index; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Set the index class |
104
|
|
|
* |
105
|
|
|
* @param BaseIndex $index |
106
|
|
|
*/ |
107
|
14 |
|
public function setIndex(BaseIndex $index): void |
108
|
|
|
{ |
109
|
14 |
|
$this->index = $index; |
110
|
14 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get the amount of CPU Cores configured |
114
|
|
|
* |
115
|
|
|
* @return int |
116
|
|
|
*/ |
117
|
3 |
|
public function getCores(): int |
118
|
|
|
{ |
119
|
3 |
|
return $this->cores; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Set the amount of CPU Cores to use |
124
|
|
|
* |
125
|
|
|
* @param int $cores |
126
|
|
|
*/ |
127
|
16 |
|
public function setCores(int $cores): void |
128
|
|
|
{ |
129
|
16 |
|
$this->cores = $cores; |
130
|
16 |
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get the length of a single batch |
134
|
|
|
* |
135
|
|
|
* @return int |
136
|
|
|
*/ |
137
|
13 |
|
public function getBatchLength(): int |
138
|
|
|
{ |
139
|
13 |
|
return $this->batchLength; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Set the length of a single batch |
144
|
|
|
* |
145
|
|
|
* @param int $batchLength |
146
|
|
|
*/ |
147
|
16 |
|
public function setBatchLength(int $batchLength): void |
148
|
|
|
{ |
149
|
16 |
|
$this->batchLength = $batchLength; |
150
|
16 |
|
} |
151
|
|
|
} |
152
|
|
|
|