|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\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\Access\Rootline; |
|
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ApacheSolrDocument\Builder; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\FieldProcessor\Service; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\PageFieldMappingIndexer; |
|
31
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\Item; |
|
32
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
|
33
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
|
34
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document; |
|
35
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection; |
|
36
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
37
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Page Indexer to index TYPO3 pages used by the Index Queue. |
|
41
|
|
|
* |
|
42
|
|
|
* @author Ingo Renner <[email protected]> |
|
43
|
|
|
* @author Daniel Poetzinger <[email protected]> |
|
44
|
|
|
* @author Timo Schmidt <[email protected]> |
|
45
|
|
|
*/ |
|
46
|
|
|
class Typo3PageIndexer |
|
47
|
|
|
{ |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* ID of the current page's Solr document. |
|
51
|
|
|
* |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
protected static $pageSolrDocumentId = ''; |
|
55
|
|
|
/** |
|
56
|
|
|
* The Solr document generated for the current page. |
|
57
|
|
|
* |
|
58
|
|
|
* @var Document |
|
59
|
|
|
*/ |
|
60
|
|
|
protected static $pageSolrDocument = null; |
|
61
|
|
|
/** |
|
62
|
|
|
* The mount point parameter used in the Frontend controller. |
|
63
|
|
|
* |
|
64
|
|
|
* @var string |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $mountPointParameter; |
|
67
|
|
|
/** |
|
68
|
|
|
* Solr server connection. |
|
69
|
|
|
* |
|
70
|
|
|
* @var SolrConnection |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $solrConnection = null; |
|
73
|
|
|
/** |
|
74
|
|
|
* Frontend page object (TSFE). |
|
75
|
|
|
* |
|
76
|
|
|
* @var TypoScriptFrontendController |
|
77
|
|
|
*/ |
|
78
|
|
|
protected $page = null; |
|
79
|
|
|
/** |
|
80
|
|
|
* Content extractor to extract content from TYPO3 pages |
|
81
|
|
|
* |
|
82
|
|
|
* @var Typo3PageContentExtractor |
|
83
|
|
|
*/ |
|
84
|
|
|
protected $contentExtractor = null; |
|
85
|
|
|
/** |
|
86
|
|
|
* URL to be indexed as the page's URL |
|
87
|
|
|
* |
|
88
|
|
|
* @var string |
|
89
|
|
|
*/ |
|
90
|
|
|
protected $pageUrl = ''; |
|
91
|
|
|
/** |
|
92
|
|
|
* The page's access rootline |
|
93
|
|
|
* |
|
94
|
|
|
* @var Rootline |
|
95
|
|
|
*/ |
|
96
|
|
|
protected $pageAccessRootline = null; |
|
97
|
|
|
/** |
|
98
|
|
|
* Documents that have been sent to Solr |
|
99
|
|
|
* |
|
100
|
|
|
* @var array |
|
101
|
|
|
*/ |
|
102
|
|
|
protected $documentsSentToSolr = []; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @var TypoScriptConfiguration |
|
106
|
|
|
*/ |
|
107
|
|
|
protected $configuration; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @var Item |
|
111
|
|
|
*/ |
|
112
|
|
|
protected $indexQueueItem; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager |
|
116
|
|
|
*/ |
|
117
|
|
|
protected $logger = null; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Constructor |
|
121
|
|
|
* |
|
122
|
|
|
* @param TypoScriptFrontendController $page The page to index |
|
123
|
|
|
*/ |
|
124
|
68 |
|
public function __construct(TypoScriptFrontendController $page) |
|
125
|
|
|
{ |
|
126
|
68 |
|
$this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__); |
|
127
|
|
|
|
|
128
|
68 |
|
$this->page = $page; |
|
129
|
68 |
|
$this->pageUrl = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'); |
|
130
|
68 |
|
$this->configuration = Util::getSolrConfiguration(); |
|
131
|
|
|
|
|
132
|
|
|
try { |
|
133
|
68 |
|
$this->initializeSolrConnection(); |
|
134
|
2 |
|
} catch (\Exception $e) { |
|
135
|
2 |
|
$this->logger->log( |
|
136
|
2 |
|
SolrLogManager::ERROR, |
|
137
|
2 |
|
$e->getMessage() . ' Error code: ' . $e->getCode() |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
// TODO extract to a class "ExceptionLogger" |
|
141
|
2 |
|
if ($this->configuration->getLoggingExceptions()) { |
|
142
|
2 |
|
$this->logger->log( |
|
143
|
2 |
|
SolrLogManager::ERROR, |
|
144
|
2 |
|
'Exception while trying to index a page', |
|
145
|
|
|
[ |
|
146
|
2 |
|
$e->__toString() |
|
147
|
|
|
] |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
68 |
|
$this->pageAccessRootline = GeneralUtility::makeInstance(Rootline::class, /** @scrutinizer ignore-type */ ''); |
|
153
|
68 |
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param Item $indexQueueItem |
|
157
|
|
|
*/ |
|
158
|
10 |
|
public function setIndexQueueItem($indexQueueItem) |
|
159
|
|
|
{ |
|
160
|
10 |
|
$this->indexQueueItem = $indexQueueItem; |
|
161
|
10 |
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Initializes the Solr server connection. |
|
165
|
|
|
* |
|
166
|
|
|
* @throws \Exception when no Solr connection can be established. |
|
167
|
|
|
*/ |
|
168
|
68 |
|
protected function initializeSolrConnection() |
|
169
|
|
|
{ |
|
170
|
68 |
|
$solr = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($this->page->id, Util::getLanguageUid()); |
|
171
|
|
|
|
|
172
|
|
|
// do not continue if no server is available |
|
173
|
66 |
|
if (!$solr->getWriteService()->ping()) { |
|
174
|
|
|
throw new \Exception( |
|
175
|
|
|
'No Solr instance available while trying to index a page.', |
|
176
|
|
|
1234790825 |
|
177
|
|
|
); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
66 |
|
$this->solrConnection = $solr; |
|
181
|
66 |
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Gets the current page's Solr document ID. |
|
185
|
|
|
* |
|
186
|
|
|
* @return string|NULL The page's Solr document ID or NULL in case no document was generated yet. |
|
187
|
|
|
*/ |
|
188
|
|
|
public static function getPageSolrDocumentId() |
|
189
|
|
|
{ |
|
190
|
|
|
return self::$pageSolrDocumentId; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Gets the Solr document generated for the current page. |
|
195
|
|
|
* |
|
196
|
|
|
* @return Document|NULL The page's Solr document or NULL if it has not been generated yet. |
|
197
|
|
|
*/ |
|
198
|
10 |
|
public static function getPageSolrDocument() |
|
199
|
|
|
{ |
|
200
|
10 |
|
return self::$pageSolrDocument; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Allows to provide a Solr server connection other than the one |
|
205
|
|
|
* initialized by the constructor. |
|
206
|
|
|
* |
|
207
|
|
|
* @param SolrConnection $solrConnection Solr connection |
|
208
|
|
|
* @throws \Exception if the Solr server cannot be reached |
|
209
|
|
|
*/ |
|
210
|
10 |
|
public function setSolrConnection(SolrConnection $solrConnection) |
|
211
|
|
|
{ |
|
212
|
10 |
|
if (!$solrConnection->getWriteService()->ping()) { |
|
213
|
|
|
throw new \Exception( |
|
214
|
|
|
'Could not connect to Solr server.', |
|
215
|
|
|
1323946472 |
|
216
|
|
|
); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
10 |
|
$this->solrConnection = $solrConnection; |
|
220
|
10 |
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Indexes a page. |
|
224
|
|
|
* |
|
225
|
|
|
* @return bool TRUE after successfully indexing the page, FALSE on error |
|
226
|
|
|
* @throws \UnexpectedValueException if a page document post processor fails to implement interface ApacheSolrForTypo3\Solr\PageDocumentPostProcessor |
|
227
|
|
|
*/ |
|
228
|
68 |
|
public function indexPage() |
|
229
|
|
|
{ |
|
230
|
68 |
|
$pageIndexed = false; |
|
231
|
68 |
|
$documents = []; // this will become useful as soon as when starting to index individual records instead of whole pages |
|
232
|
|
|
|
|
233
|
68 |
|
if (is_null($this->solrConnection)) { |
|
234
|
|
|
// intended early return as it doesn't make sense to continue |
|
235
|
|
|
// and waste processing time if the solr server isn't available |
|
236
|
|
|
// anyways |
|
237
|
|
|
// FIXME use an exception |
|
238
|
|
|
return $pageIndexed; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
68 |
|
$pageDocument = $this->getPageDocument(); |
|
242
|
68 |
|
$pageDocument = $this->substitutePageDocument($pageDocument); |
|
243
|
|
|
|
|
244
|
68 |
|
$this->applyIndexPagePostProcessors($pageDocument); |
|
245
|
|
|
|
|
246
|
68 |
|
self::$pageSolrDocument = $pageDocument; |
|
247
|
68 |
|
$documents[] = $pageDocument; |
|
248
|
68 |
|
$documents = $this->getAdditionalDocuments($pageDocument, $documents); |
|
249
|
68 |
|
$this->processDocuments($documents); |
|
250
|
|
|
|
|
251
|
68 |
|
$pageIndexed = $this->addDocumentsToSolrIndex($documents); |
|
252
|
68 |
|
$this->documentsSentToSolr = $documents; |
|
253
|
|
|
|
|
254
|
68 |
|
return $pageIndexed; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Applies the configured post processors (indexPagePostProcessPageDocument) |
|
259
|
|
|
* |
|
260
|
|
|
* @param Document $pageDocument |
|
261
|
|
|
*/ |
|
262
|
68 |
|
protected function applyIndexPagePostProcessors($pageDocument) |
|
263
|
|
|
{ |
|
264
|
68 |
|
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPagePostProcessPageDocument'])) { |
|
265
|
67 |
|
return; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
1 |
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPagePostProcessPageDocument'] as $classReference) { |
|
269
|
1 |
|
$postProcessor = GeneralUtility::makeInstance($classReference); |
|
270
|
1 |
|
if (!$postProcessor instanceof PageDocumentPostProcessor) { |
|
271
|
|
|
throw new \UnexpectedValueException(get_class($pageDocument) . ' must implement interface ' . PageDocumentPostProcessor::class, 1397739154); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
1 |
|
$postProcessor->postProcessPageDocument($pageDocument, $this->page); |
|
275
|
|
|
} |
|
276
|
1 |
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Builds the Solr document for the current page. |
|
280
|
|
|
* |
|
281
|
|
|
* @return Document A document representing the page |
|
282
|
|
|
*/ |
|
283
|
68 |
|
protected function getPageDocument() |
|
284
|
|
|
{ |
|
285
|
68 |
|
$documentBuilder = GeneralUtility::makeInstance(Builder::class); |
|
286
|
68 |
|
$document = $documentBuilder->fromPage($this->page, $this->pageUrl, $this->pageAccessRootline, (string)$this->mountPointParameter); |
|
287
|
|
|
|
|
288
|
68 |
|
self::$pageSolrDocumentId = $document['id']; |
|
289
|
|
|
|
|
290
|
68 |
|
return $document; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
|
|
294
|
|
|
// Logging |
|
295
|
|
|
// TODO replace by a central logger |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* Gets the mount point parameter that is used in the Frontend controller. |
|
299
|
|
|
* |
|
300
|
|
|
* @return string |
|
301
|
|
|
*/ |
|
302
|
|
|
public function getMountPointParameter() |
|
303
|
|
|
{ |
|
304
|
|
|
return $this->mountPointParameter; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
// Misc |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Sets the mount point parameter that is used in the Frontend controller. |
|
311
|
|
|
* |
|
312
|
|
|
* @param string $mountPointParameter |
|
313
|
|
|
*/ |
|
314
|
10 |
|
public function setMountPointParameter($mountPointParameter) |
|
315
|
|
|
{ |
|
316
|
10 |
|
$this->mountPointParameter = (string)$mountPointParameter; |
|
317
|
10 |
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* Allows third party extensions to replace or modify the page document |
|
321
|
|
|
* created by this indexer. |
|
322
|
|
|
* |
|
323
|
|
|
* @param Document $pageDocument The page document created by this indexer. |
|
324
|
|
|
* @return Document An Apache Solr document representing the currently indexed page |
|
325
|
|
|
*/ |
|
326
|
68 |
|
protected function substitutePageDocument(Document $pageDocument) |
|
327
|
|
|
{ |
|
328
|
68 |
|
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageSubstitutePageDocument'])) { |
|
329
|
20 |
|
return $pageDocument; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
48 |
|
$indexConfigurationName = $this->getIndexConfigurationNameForCurrentPage(); |
|
333
|
48 |
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageSubstitutePageDocument'] as $classReference) { |
|
334
|
48 |
|
$substituteIndexer = GeneralUtility::makeInstance($classReference); |
|
335
|
|
|
|
|
336
|
48 |
|
if (!$substituteIndexer instanceof SubstitutePageIndexer) { |
|
337
|
|
|
$message = get_class($substituteIndexer) . ' must implement interface ' . SubstitutePageIndexer::class; |
|
338
|
|
|
throw new \UnexpectedValueException($message, 1310491001); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
48 |
|
if ($substituteIndexer instanceof PageFieldMappingIndexer) { |
|
342
|
48 |
|
$substituteIndexer->setPageIndexingConfigurationName($indexConfigurationName); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
48 |
|
$substituteDocument = $substituteIndexer->getPageDocument($pageDocument); |
|
346
|
48 |
|
if (!$substituteDocument instanceof Document) { |
|
347
|
|
|
$message = 'The document returned by ' . get_class($substituteIndexer) . ' is not a valid Document object.'; |
|
348
|
|
|
throw new \UnexpectedValueException($message, 1310490952); |
|
349
|
|
|
} |
|
350
|
48 |
|
$pageDocument = $substituteDocument; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
48 |
|
return $pageDocument; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* Retrieves the indexConfigurationName from the related queueItem, or falls back to pages when no queue item set. |
|
358
|
|
|
* |
|
359
|
|
|
* @return string |
|
360
|
|
|
*/ |
|
361
|
48 |
|
protected function getIndexConfigurationNameForCurrentPage() |
|
362
|
|
|
{ |
|
363
|
48 |
|
return isset($this->indexQueueItem) ? $this->indexQueueItem->getIndexingConfigurationName() : 'pages'; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* Allows third party extensions to provide additional documents which |
|
368
|
|
|
* should be indexed for the current page. |
|
369
|
|
|
* |
|
370
|
|
|
* @param Document $pageDocument The main document representing this page. |
|
371
|
|
|
* @param Document[] $existingDocuments An array of documents already created for this page. |
|
372
|
|
|
* @return array An array of additional Document objects to index |
|
373
|
|
|
*/ |
|
374
|
68 |
|
protected function getAdditionalDocuments(Document $pageDocument, array $existingDocuments) |
|
375
|
|
|
{ |
|
376
|
68 |
|
$documents = $existingDocuments; |
|
377
|
|
|
|
|
378
|
68 |
|
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments'])) { |
|
379
|
67 |
|
return $documents; |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
1 |
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments'] as $classReference) { |
|
383
|
1 |
|
$additionalIndexer = GeneralUtility::makeInstance($classReference); |
|
384
|
|
|
|
|
385
|
1 |
|
if (!$additionalIndexer instanceof AdditionalPageIndexer) { |
|
386
|
|
|
$message = get_class($additionalIndexer) . ' must implement interface ' . AdditionalPageIndexer::class; |
|
387
|
|
|
throw new \UnexpectedValueException($message, 1310491024); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
1 |
|
$additionalDocuments = $additionalIndexer->getAdditionalPageDocuments($pageDocument, $documents); |
|
391
|
1 |
|
if (is_array($additionalDocuments)) { |
|
392
|
1 |
|
$documents = array_merge($documents, $additionalDocuments); |
|
393
|
|
|
} |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
1 |
|
return $documents; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Sends the given documents to the field processing service which takes |
|
401
|
|
|
* care of manipulating fields as defined in the field's configuration. |
|
402
|
|
|
* |
|
403
|
|
|
* @param array $documents An array of documents to manipulate |
|
404
|
|
|
*/ |
|
405
|
68 |
|
protected function processDocuments(array $documents) |
|
406
|
|
|
{ |
|
407
|
68 |
|
$processingInstructions = $this->configuration->getIndexFieldProcessingInstructionsConfiguration(); |
|
408
|
68 |
|
if (count($processingInstructions) > 0) { |
|
409
|
68 |
|
$service = GeneralUtility::makeInstance(Service::class); |
|
410
|
68 |
|
$service->processDocuments($documents, $processingInstructions); |
|
411
|
|
|
} |
|
412
|
68 |
|
} |
|
413
|
|
|
|
|
414
|
|
|
/** |
|
415
|
|
|
* Adds the collected documents to the Solr index. |
|
416
|
|
|
* |
|
417
|
|
|
* @param array $documents An array of Document objects. |
|
418
|
|
|
* @return bool TRUE if documents were added successfully, FALSE otherwise |
|
419
|
|
|
*/ |
|
420
|
68 |
|
protected function addDocumentsToSolrIndex(array $documents) |
|
421
|
|
|
{ |
|
422
|
68 |
|
$documentsAdded = false; |
|
423
|
|
|
|
|
424
|
68 |
|
if (!count($documents)) { |
|
425
|
|
|
return $documentsAdded; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
try { |
|
429
|
68 |
|
$this->logger->log(SolrLogManager::INFO, 'Adding ' . count($documents) . ' documents.', $documents); |
|
430
|
|
|
|
|
431
|
|
|
// chunk adds by 20 |
|
432
|
68 |
|
$documentChunks = array_chunk($documents, 20); |
|
433
|
68 |
|
foreach ($documentChunks as $documentChunk) { |
|
434
|
68 |
|
$response = $this->solrConnection->getWriteService()->addDocuments($documentChunk); |
|
435
|
68 |
|
if ($response->getHttpStatus() != 200) { |
|
436
|
68 |
|
throw new \RuntimeException('Solr Request failed.', 1331834983); |
|
437
|
|
|
} |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
68 |
|
$documentsAdded = true; |
|
441
|
|
|
} catch (\Exception $e) { |
|
442
|
|
|
$this->logger->log(SolrLogManager::ERROR, $e->getMessage() . ' Error code: ' . $e->getCode()); |
|
443
|
|
|
|
|
444
|
|
|
if ($this->configuration->getLoggingExceptions()) { |
|
445
|
|
|
$this->logger->log(SolrLogManager::ERROR, 'Exception while adding documents', [$e->__toString()]); |
|
446
|
|
|
} |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
68 |
|
return $documentsAdded; |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
/** |
|
453
|
|
|
* Gets the current page's URL. |
|
454
|
|
|
* |
|
455
|
|
|
* @return string URL of the current page. |
|
456
|
|
|
*/ |
|
457
|
|
|
public function getPageUrl() |
|
458
|
|
|
{ |
|
459
|
|
|
return $this->pageUrl; |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
/** |
|
463
|
|
|
* Sets the URL to use for the page document. |
|
464
|
|
|
* |
|
465
|
|
|
* @param string $url The page's URL. |
|
466
|
|
|
*/ |
|
467
|
10 |
|
public function setPageUrl($url) |
|
468
|
|
|
{ |
|
469
|
10 |
|
$this->pageUrl = $url; |
|
470
|
10 |
|
} |
|
471
|
|
|
|
|
472
|
|
|
/** |
|
473
|
|
|
* Gets the page's access rootline. |
|
474
|
|
|
* |
|
475
|
|
|
* @return Rootline The page's access rootline |
|
476
|
|
|
*/ |
|
477
|
|
|
public function getPageAccessRootline() |
|
478
|
|
|
{ |
|
479
|
|
|
return $this->pageAccessRootline; |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* Sets the page's access rootline. |
|
484
|
|
|
* |
|
485
|
|
|
* @param Rootline $accessRootline The page's access rootline |
|
486
|
|
|
*/ |
|
487
|
23 |
|
public function setPageAccessRootline(Rootline $accessRootline) |
|
488
|
|
|
{ |
|
489
|
23 |
|
$this->pageAccessRootline = $accessRootline; |
|
490
|
23 |
|
} |
|
491
|
|
|
|
|
492
|
|
|
/** |
|
493
|
|
|
* Gets the documents that have been sent to Solr |
|
494
|
|
|
* |
|
495
|
|
|
* @return array An array of Document objects |
|
496
|
|
|
*/ |
|
497
|
10 |
|
public function getDocumentsSentToSolr() |
|
498
|
|
|
{ |
|
499
|
10 |
|
return $this->documentsSentToSolr; |
|
500
|
|
|
} |
|
501
|
|
|
} |
|
502
|
|
|
|