1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\System\Solr; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2009-2015 Ingo Renner <[email protected]> |
8
|
|
|
* All rights reserved |
9
|
|
|
* |
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
11
|
|
|
* free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* The GNU General Public License can be found at |
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
18
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
28
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
29
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SchemaParser; |
30
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Parser\StopWordParser; |
31
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SynonymParser; |
32
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Service\AbstractSolrService; |
33
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Service\SolrAdminService; |
34
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Service\SolrReadService; |
35
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Service\SolrWriteService; |
36
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Solr Service Access |
40
|
|
|
* |
41
|
|
|
* @author Ingo Renner <[email protected]> |
42
|
|
|
*/ |
43
|
|
|
class SolrConnection |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @var SolrAdminService |
47
|
|
|
*/ |
48
|
|
|
protected $adminService; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var SolrReadService |
52
|
|
|
*/ |
53
|
|
|
protected $readService; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var SolrWriteService |
57
|
|
|
*/ |
58
|
|
|
protected $writeService; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var TypoScriptConfiguration |
62
|
|
|
*/ |
63
|
|
|
protected $configuration; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var SynonymParser |
67
|
|
|
*/ |
68
|
|
|
protected $synonymParser = null; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var StopWordParser |
72
|
|
|
*/ |
73
|
|
|
protected $stopWordParser = null; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var SchemaParser |
77
|
|
|
*/ |
78
|
|
|
protected $schemaParser = null; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
protected $host = ''; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
protected $port = '8983'; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var string |
92
|
|
|
*/ |
93
|
|
|
protected $path = '/solr/'; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var string |
97
|
|
|
*/ |
98
|
|
|
protected $scheme = 'http'; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var string |
102
|
|
|
*/ |
103
|
|
|
protected $username = ''; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var string |
107
|
|
|
*/ |
108
|
|
|
protected $password = ''; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var SolrLogManager |
112
|
|
|
*/ |
113
|
|
|
protected $logger = null; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Constructor |
117
|
|
|
* |
118
|
|
|
* @param string $host Solr host |
119
|
|
|
* @param string $port Solr port |
120
|
|
|
* @param string $path Solr path |
121
|
|
|
* @param string $scheme Scheme, defaults to http, can be https |
122
|
|
|
* @param TypoScriptConfiguration $typoScriptConfiguration |
123
|
|
|
* @param SynonymParser $synonymParser |
124
|
|
|
* @param StopWordParser $stopWordParser |
125
|
|
|
* @param SchemaParser $schemaParser |
126
|
|
|
* @param SolrLogManager $logManager |
127
|
|
|
*/ |
128
|
112 |
|
public function __construct( |
129
|
|
|
$host = '', |
130
|
|
|
$port = '8983', |
131
|
|
|
$path = '/solr/', |
132
|
|
|
$scheme = 'http', |
133
|
|
|
$username = '', |
134
|
|
|
$password = '', |
135
|
|
|
TypoScriptConfiguration $typoScriptConfiguration = null, |
136
|
|
|
SynonymParser $synonymParser = null, |
137
|
|
|
StopWordParser $stopWordParser = null, |
138
|
|
|
SchemaParser $schemaParser = null, |
139
|
|
|
SolrLogManager $logManager = null |
140
|
|
|
) { |
141
|
112 |
|
$this->host = $host; |
142
|
112 |
|
$this->port = $port; |
143
|
112 |
|
$this->path = $path; |
144
|
112 |
|
$this->scheme = $scheme; |
145
|
112 |
|
$this->username = $username; |
146
|
112 |
|
$this->password = $password; |
147
|
112 |
|
$this->configuration = $typoScriptConfiguration; |
148
|
112 |
|
$this->synonymParser = $synonymParser; |
149
|
112 |
|
$this->stopWordParser = $stopWordParser; |
150
|
112 |
|
$this->schemaParser = $schemaParser; |
151
|
112 |
|
$this->logger = $logManager; |
152
|
112 |
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return SolrAdminService |
156
|
|
|
*/ |
157
|
8 |
|
public function getAdminService() |
158
|
|
|
{ |
159
|
8 |
|
if ($this->adminService === null) { |
160
|
8 |
|
$this->adminService = $this->buildAdminService(); |
161
|
|
|
} |
162
|
|
|
|
163
|
8 |
|
return $this->initializeService($this->adminService); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return SolrAdminService |
168
|
|
|
*/ |
169
|
6 |
|
protected function buildAdminService() |
170
|
|
|
{ |
171
|
6 |
|
return GeneralUtility::makeInstance(SolrAdminService::class, $this->host, $this->port, $this->path, $this->scheme, $this->configuration, $this->logger, $this->synonymParser, $this->stopWordParser, $this->schemaParser); |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return SolrReadService |
176
|
|
|
*/ |
177
|
51 |
|
public function getReadService() |
178
|
|
|
{ |
179
|
51 |
|
if ($this->readService === null) { |
180
|
51 |
|
$this->readService = $this->buildReadService(); |
181
|
|
|
} |
182
|
|
|
|
183
|
50 |
|
return $this->initializeService($this->readService); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return SolrReadService |
188
|
|
|
*/ |
189
|
51 |
|
protected function buildReadService() |
190
|
|
|
{ |
191
|
51 |
|
return GeneralUtility::makeInstance(SolrReadService::class, $this->host, $this->port, $this->path, $this->scheme, $this->configuration, $this->logger); |
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return SolrWriteService |
196
|
|
|
*/ |
197
|
90 |
|
public function getWriteService() |
198
|
|
|
{ |
199
|
90 |
|
if ($this->writeService === null) { |
200
|
90 |
|
$this->writeService = $this->buildWriteService(); |
201
|
|
|
} |
202
|
|
|
|
203
|
90 |
|
return $this->initializeService($this->writeService); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return SolrWriteService |
208
|
|
|
*/ |
209
|
90 |
|
protected function buildWriteService() |
210
|
|
|
{ |
211
|
90 |
|
return GeneralUtility::makeInstance(SolrWriteService::class, $this->host, $this->port, $this->path, $this->scheme, $this->configuration, $this->logger); |
|
|
|
|
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param AbstractSolrService $service |
216
|
|
|
* @return AbstractSolrService |
217
|
|
|
*/ |
218
|
103 |
|
protected function initializeService(AbstractSolrService $service) { |
219
|
103 |
|
if (trim($this->username) !== '') { |
220
|
|
|
$service->setAuthenticationCredentials($this->username, $this->password); |
221
|
|
|
} |
222
|
|
|
|
223
|
103 |
|
return $service; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Creates a string representation of the Solr connection. Specifically |
228
|
|
|
* will return the Solr URL. |
229
|
|
|
* |
230
|
|
|
* @return string The Solr URL. |
231
|
|
|
*/ |
232
|
10 |
|
public function __toString() |
233
|
|
|
{ |
234
|
10 |
|
return $this->scheme . '://' . $this->host . ':' . $this->port . $this->path; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|