1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\System\Solr\Service; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2009-2017 Timo Hund <[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 2 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\ExtractingQuery; |
28
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class SolrReadService |
32
|
|
|
* @package ApacheSolrForTypo3\System\Solr\Service |
33
|
|
|
*/ |
34
|
|
|
class SolrWriteService extends AbstractSolrService |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Performs a content and meta data extraction request. |
38
|
|
|
* |
39
|
|
|
* @param ExtractingQuery $query An extraction query |
40
|
|
|
* @return array An array containing the extracted content [0] and meta data [1] |
41
|
|
|
*/ |
42
|
|
|
public function extractByQuery(ExtractingQuery $query) |
43
|
|
|
{ |
44
|
|
|
$headers = [ |
45
|
|
|
'Content-Type' => 'multipart/form-data; boundary=' . $query->getMultiPartPostDataBoundary() |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
try { |
49
|
|
|
$response = $this->requestServlet( |
50
|
|
|
self::EXTRACT_SERVLET, |
51
|
|
|
$query->getQueryParameters(), |
52
|
|
|
'POST', |
53
|
|
|
$headers, |
54
|
|
|
$query->getRawPostFileData() |
55
|
|
|
); |
56
|
|
|
} catch (\Exception $e) { |
57
|
|
|
$this->logger->log( |
58
|
|
|
SolrLogManager::ERROR, |
59
|
|
|
'Extracting text and meta data through Solr Cell over HTTP POST', |
60
|
|
|
[ |
61
|
|
|
'query' => (array)$query, |
62
|
|
|
'parameters' => $query->getQueryParameters(), |
63
|
|
|
'file' => $query->getFile(), |
64
|
|
|
'headers' => $headers, |
65
|
|
|
'query url' => self::EXTRACT_SERVLET, |
66
|
|
|
'exception' => $e->getMessage() |
67
|
|
|
] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return [ |
72
|
|
|
$response->extracted, |
73
|
|
|
(array)$response->extracted_metadata |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Deletes all index documents of a certain type and does a commit |
79
|
|
|
* afterwards. |
80
|
|
|
* |
81
|
|
|
* @param string $type The type of documents to delete, usually a table name. |
82
|
|
|
* @param bool $commit Will commit immediately after deleting the documents if set, defaults to TRUE |
83
|
|
|
*/ |
84
|
|
|
public function deleteByType($type, $commit = true) |
85
|
|
|
{ |
86
|
|
|
$this->deleteByQuery('type:' . trim($type)); |
87
|
|
|
|
88
|
|
|
if ($commit) { |
89
|
|
|
$this->commit(false, false, false); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be |
95
|
|
|
* a complete and well formed "delete" xml document |
96
|
|
|
* |
97
|
|
|
* @param string $rawPost Expected to be utf-8 encoded xml document |
98
|
|
|
* @param float|int $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) |
99
|
|
|
* @return \Apache_Solr_Response |
100
|
|
|
*/ |
101
|
|
|
public function delete($rawPost, $timeout = 3600) |
102
|
|
|
{ |
103
|
|
|
$response = $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout); |
104
|
|
|
$this->logger->log(SolrLogManager::NOTICE, 'Delete Query sent.', ['query' => $rawPost, 'query url' => $this->_updateUrl, 'response' => (array)$response]); |
105
|
|
|
|
106
|
|
|
return $response; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} |