|
1
|
|
|
<?php |
|
2
|
|
|
namespace EWW\Dpf\Services; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
use Elasticsearch\Client as Client; |
|
18
|
|
|
use EWW\Dpf\Exceptions\RepositoryConnectionErrorException; |
|
19
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
20
|
|
|
use EWW\Dpf\Configuration\ClientConfigurationManager; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class ElasticSearch |
|
24
|
|
|
* @package EWW\Dpf\Services |
|
25
|
|
|
* @deprecated since version 4.0 |
|
26
|
|
|
*/ |
|
27
|
|
|
class ElasticSearch |
|
28
|
|
|
{ |
|
29
|
|
|
protected $es; |
|
30
|
|
|
|
|
31
|
|
|
protected $server = ''; //127.0.0.1'; |
|
32
|
|
|
|
|
33
|
|
|
protected $port = '9200'; |
|
34
|
|
|
|
|
35
|
|
|
protected $index = 'fedora'; |
|
36
|
|
|
|
|
37
|
|
|
protected $type = 'object'; |
|
38
|
|
|
|
|
39
|
|
|
protected $hits; |
|
40
|
|
|
|
|
41
|
|
|
protected $resultList; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* elasticsearch client constructor |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct() |
|
47
|
|
|
{ |
|
48
|
|
|
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class); |
|
49
|
|
|
$clientConfigurationManager = $objectManager->get(ClientConfigurationManager::class); |
|
50
|
|
|
|
|
51
|
|
|
$this->server = $clientConfigurationManager->getElasticSearchHost(); |
|
52
|
|
|
$this->port = $clientConfigurationManager->getElasticSearchPort(); |
|
53
|
|
|
|
|
54
|
|
|
// initialize elasticsearch lib |
|
55
|
|
|
$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('dpf'); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$params['hosts'] = array( |
|
|
|
|
|
|
58
|
|
|
$this->server . ':' . $this->port, |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
// $client = ClientBuilder::create()->build(); |
|
62
|
|
|
$this->es = new Client($params); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* performs the |
|
68
|
|
|
* @param array $query search query |
|
69
|
|
|
* @return array result list |
|
70
|
|
|
*/ |
|
71
|
|
|
public function search($query, $type) |
|
72
|
|
|
{ |
|
73
|
|
|
try { |
|
74
|
|
|
// define type and index |
|
75
|
|
|
if (empty($query['index'])) { |
|
76
|
|
|
$query['index'] = $this->index; |
|
77
|
|
|
} |
|
78
|
|
|
if (!empty($type)) { |
|
79
|
|
|
$query['type'] = $type; |
|
80
|
|
|
// $query['type'] = $this->type; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// Search request |
|
84
|
|
|
$results = $this->es->search($query); |
|
85
|
|
|
|
|
86
|
|
|
$this->hits = $results['hits']['total']; |
|
87
|
|
|
|
|
88
|
|
|
$this->resultList = $results['hits']; |
|
89
|
|
|
|
|
90
|
|
|
return $this->resultList; |
|
91
|
|
|
} catch ( \Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost $exception) { |
|
92
|
|
|
throw new \EWW\Dpf\Exceptions\ElasticSearchConnectionErrorException("Could not connect to repository server."); |
|
93
|
|
|
} catch (\Elasticsearch\Common\Exceptions\Curl\CouldNotResolveHostException $exception) { |
|
94
|
|
|
throw new \EWW\Dpf\Exceptions\ElasticSearchConnectionErrorException("Could not connect to repository server."); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* returns the result list |
|
100
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
101
|
|
|
*/ |
|
102
|
|
|
public function getResults() |
|
103
|
|
|
{ |
|
104
|
|
|
// return results from the last search request |
|
105
|
|
|
return $this->resultList; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|