-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFulltextsearchController.php
196 lines (153 loc) · 7.13 KB
/
FulltextsearchController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2013, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
require_once realpath(dirname(__FILE__)) . '/classes/ElasticsearchHelper.php';
require_once realpath(dirname(__FILE__)) . '/classes/ElasticsearchUtils.php';
require_once realpath(dirname(__FILE__)) . '/classes/IndexServiceConnector.php';
/**
* Fulltextsearch component controller.
*
* @category OntoWiki
* @package Extensions_Fulltextsearch
* @author Sebastian Nuck
* @copyright Copyright (c) 2014, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
class FulltextsearchController extends OntoWiki_Controller_Component
{
public function fulltextsearchAction() {
// tells the OntoWiki to not apply the template to this action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$translate = $this->_owApp->translate;
if ($this->_request->query !== null) {
$searchText = htmlspecialchars(trim($this->_request->query));
}
$error = false;
$errorMsg = '';
// check if search already contains an error
if (!$error) {
$esHelper = new ElasticsearchHelper($this->_privateConfig);
// $esHelper = new ElasticsearchHelperOld();
$result = $esHelper->search($searchText);
}
// if error occured set output for error page
if ($error) {
$this->view->errorMsg = $errorMsg;
} else {
// set redirect to effective search controller
//$url = new OntoWiki_Url(array('controller' => 'list'), array());
//$url->setParam('s', $searchText);
//$url->setParam('init', '1');
//$this->_redirect($url);
}
$this->_response->setBody(json_encode($result));
}
public function searchAction() {
OntoWiki::getInstance()->logger->info('searchAction');
$translate = $this->_owApp->translate;
$this->view->placeholder('main.window.title')->set($translate->_('Fulltext Search'));
$this->addModuleContext('main.window.fulltextsearch.search');
$params = $this->_request->getParams();
$input = $params['input'];
$from = $params['from'];
$indices = '';
if (isset($params['indices'])) {
$indices = $params['indices'];
}
$this->view->input = $input;
$esHelper = new ElasticsearchHelper($this->_privateConfig);
$result = $esHelper->searchAndReturnEverything($input, $indices, $from);
$this->view->jsonResult = $result['resultSet'];
$this->view->availableIndices = $esHelper->getAvailableIndices();
// transform comma separated indices to array
$this->view->selectedIndices = str_getcsv($indices);
$this->view->resultArray = ElasticsearchUtils::extractResults($result['resultSet']);
$this->view->query = $result['query'];
$this->view->from = $from;
$this->view->input = $input;
$this->view->hits = $result['resultSet']['hits']['total'];
OntoWiki::getInstance()->getNavigation()->disableNavigation();
}
/**
* Displays an information page.
* @return [type]
*/
public function infoAction() {
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->logger;
$translate = $this->_owApp->translate;
$this->view->placeholder('main.window.title')->set($translate->_('Fulltext Search Info'));
$this->addModuleContext('main.window.fulltextsearch.info');
$_owApp->getNavigation()->disableNavigation();
$esHelper = new ElasticsearchHelper($this->_privateConfig);
$indices = $esHelper->getAvailableIndicesWithMetadata();
$this->view->indices = $indices;
}
/**
* Creates a new index, requires indexname parameter.
* @return [type]
*/
public function createindexAction() {
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->logger;
// tells the OntoWiki to not apply the template to this action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$params = $this->_request->getParams();
$indexname = $params['indexname'];
$indexServiceConnector = new IndexServiceConnector($this->_privateConfig);
$response = $indexServiceConnector->triggerCreateIndex($indexname);
$indexServiceConnector->finish();
$_owApp->logger->debug('Fulltextsearch createindexAction response:' . $response);
// $this->_response->setHeader('Content-Type', 'text/html');
$this->_response->setBody(json_encode($response));
}
public function deleteindexAction() {
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->logger;
// tells the OntoWiki to not apply the template to this action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$params = $this->_request->getParams();
$indexname = $params['indexname'];
$_owApp->logger->debug('Fulltextsearch deleteindexAction: deleting index: ' . $indexname);
$indexServiceConnector = new IndexServiceConnector($this->_privateConfig);
$response = $indexServiceConnector->triggerDeleteIndex($indexname);
$indexServiceConnector->finish();
$this->_response->setHeader('Content-Type', 'text/html');
$this->_response->setBody($response);
$url = OntoWiki::getInstance()->getUrlBase() . 'fulltextsearch/info';
if ($response === 'true') {
$this->_redirect($url, array('code' => 302));
} else {
$this->_redirect($url, array('code' => 500));
}
}
public function reindexclassAction() {
$_owApp = OntoWiki::getInstance();
$logger = $_owApp->logger;
// tells the OntoWiki to not apply the template to this action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$params = $this->_request->getParams();
if (isset($params['indexname'])) {
$indexname = $params['indexname'];
} else {
$indexname = null;
}
$indexServiceConnector = new IndexServiceConnector($this->_privateConfig);
$response = $indexServiceConnector->triggerReindexClass($indexname);
$indexServiceConnector->finish();
$url = OntoWiki::getInstance()->getUrlBase() . 'fulltextsearch/info';
if ($response === 'true') {
$this->_redirect($url, array('code' => 302));
} else {
$this->_redirect($url, array('code' => 500));
}
}
}