1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Bookmarks_FullTextSearch - Indexing bookmarks |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Maxence Lange <[email protected]> |
9
|
|
|
* @copyright 2018 |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OCA\Bookmarks_FullTextSearch\Provider; |
28
|
|
|
|
29
|
|
|
use OCA\Bookmarks_FullTextSearch\AppInfo\Application; |
30
|
|
|
use OCA\Bookmarks_FullTextSearch\Model\BookmarksDocument; |
31
|
|
|
use OCA\Bookmarks_FullTextSearch\Service\BookmarksService; |
32
|
|
|
use OCA\Bookmarks_FullTextSearch\Service\ConfigService; |
33
|
|
|
use OCA\Bookmarks_FullTextSearch\Service\ElasticSearchService; |
34
|
|
|
use OCA\Bookmarks_FullTextSearch\Service\MiscService; |
35
|
|
|
use OCA\Bookmarks_FullTextSearch\Service\SearchService; |
36
|
|
|
use OCA\FullTextSearch\IFullTextSearchPlatform; |
37
|
|
|
use OCA\FullTextSearch\IFullTextSearchProvider; |
38
|
|
|
use OCA\FullTextSearch\Model\Index; |
39
|
|
|
use OCA\FullTextSearch\Model\IndexDocument; |
40
|
|
|
use OCA\FullTextSearch\Model\Runner; |
41
|
|
|
use OCA\FullTextSearch\Model\SearchRequest; |
42
|
|
|
use OCA\FullTextSearch\Model\SearchResult; |
43
|
|
|
use OCP\AppFramework\QueryException; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
class BookmarksProvider implements IFullTextSearchProvider { |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
const BOOKMARKS_PROVIDER_ID = 'bookmarks'; |
50
|
|
|
|
51
|
|
|
/** @var ConfigService */ |
52
|
|
|
private $configService; |
53
|
|
|
|
54
|
|
|
/** @var BookmarksService */ |
55
|
|
|
private $bookmarksService; |
56
|
|
|
|
57
|
|
|
/** @var SearchService */ |
58
|
|
|
private $searchService; |
59
|
|
|
|
60
|
|
|
/** @var ElasticSearchService */ |
61
|
|
|
private $elasticSearchService; |
62
|
|
|
|
63
|
|
|
/** @var MiscService */ |
64
|
|
|
private $miscService; |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** @var Runner */ |
68
|
|
|
private $runner; |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* return unique id of the provider |
73
|
|
|
*/ |
74
|
|
|
public function getId() { |
75
|
|
|
return self::BOOKMARKS_PROVIDER_ID; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* return name of the provider |
81
|
|
|
*/ |
82
|
|
|
public function getName() { |
83
|
|
|
return 'Bookmarks'; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getVersion() { |
91
|
|
|
return $this->configService->getAppValue('installed_version'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getAppId() { |
99
|
|
|
return Application::APP_NAME; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
public function getConfiguration() { |
107
|
|
|
return $this->configService->getConfig(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function setRunner(Runner $runner) { |
112
|
|
|
$this->runner = $runner; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function getOptionsTemplate() { |
120
|
|
|
return ''; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* called when loading all providers. |
126
|
|
|
* |
127
|
|
|
* Loading some containers. |
128
|
|
|
* |
129
|
|
|
* @throws QueryException |
130
|
|
|
*/ |
131
|
|
|
public function loadProvider() { |
132
|
|
|
$app = new Application(); |
133
|
|
|
|
134
|
|
|
$container = $app->getContainer(); |
135
|
|
|
$this->configService = $container->query(ConfigService::class); |
136
|
|
|
$this->bookmarksService = $container->query(BookmarksService::class); |
137
|
|
|
$this->searchService = $container->query(SearchService::class); |
138
|
|
|
$this->elasticSearchService = $container->query(ElasticSearchService::class); |
139
|
|
|
$this->miscService = $container->query(MiscService::class); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* returns all indexable document for a user. |
145
|
|
|
* There is no need to fill the document with content at this point. |
146
|
|
|
* |
147
|
|
|
* $platform is provided if the mapping needs to be changed. |
148
|
|
|
* |
149
|
|
|
* @param string $userId |
150
|
|
|
* |
151
|
|
|
* @return BookmarksDocument[] |
152
|
|
|
*/ |
153
|
|
|
public function generateIndexableDocuments($userId) { |
154
|
|
|
$bookmarks = $this->bookmarksService->getBookmarksFromUser($this->runner, $userId); |
155
|
|
|
|
156
|
|
|
return $bookmarks; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* generate documents prior to the indexing. |
162
|
|
|
* throw NoResultException if no more result |
163
|
|
|
* |
164
|
|
|
* @param IndexDocument[] $chunk |
165
|
|
|
* |
166
|
|
|
* @return IndexDocument[] |
167
|
|
|
*/ |
168
|
|
|
public function fillIndexDocuments($chunk) { |
169
|
|
|
|
170
|
|
|
/** @var BookmarksDocument[] $chunk */ |
171
|
|
|
$result = $this->bookmarksService->generateDocuments($chunk); |
172
|
|
|
|
173
|
|
|
return $result; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param IndexDocument $document |
179
|
|
|
* |
180
|
|
|
* @return bool |
181
|
|
|
*/ |
182
|
|
|
public function isDocumentUpToDate($document) { |
183
|
|
|
return $this->bookmarksService->isDocumentUpToDate($document); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param Index $index |
189
|
|
|
* |
190
|
|
|
* @return BookmarksDocument|null |
191
|
|
|
*/ |
192
|
|
|
public function updateDocument(Index $index) { |
193
|
|
|
return $this->bookmarksService->updateDocument($index); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param IFullTextSearchPlatform $platform |
199
|
|
|
*/ |
200
|
|
|
public function onInitializingIndex(IFullTextSearchPlatform $platform) { |
201
|
|
|
$this->elasticSearchService->onInitializingIndex($platform); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param IFullTextSearchPlatform $platform |
206
|
|
|
* @param array $arr |
207
|
|
|
*/ |
208
|
|
|
public function onIndexingDocument(IFullTextSearchPlatform $platform, &$arr) { |
209
|
|
|
$this->elasticSearchService->onIndexingDocument($platform, $arr); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param IFullTextSearchPlatform $platform |
214
|
|
|
*/ |
215
|
|
|
public function onResettingIndex(IFullTextSearchPlatform $platform) { |
216
|
|
|
$this->elasticSearchService->onResettingIndex($platform); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param IFullTextSearchPlatform $platform |
221
|
|
|
* @param SearchRequest $request |
222
|
|
|
* @param array $arr |
223
|
|
|
*/ |
224
|
|
|
public function onSearchingQuery( |
225
|
|
|
IFullTextSearchPlatform $platform, SearchRequest $request, &$arr |
226
|
|
|
) { |
227
|
|
|
$this->elasticSearchService->onSearchingQuery($platform, $request, $arr); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* not used yet |
233
|
|
|
*/ |
234
|
|
|
public function unloadProvider() { |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* before a search, improve the request |
240
|
|
|
* |
241
|
|
|
* @param SearchRequest $request |
242
|
|
|
*/ |
243
|
|
|
public function improveSearchRequest(SearchRequest $request) { |
244
|
|
|
$this->searchService->improveSearchRequest($request); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* after a search, improve results |
250
|
|
|
* |
251
|
|
|
* @param SearchResult $searchResult |
252
|
|
|
*/ |
253
|
|
|
public function improveSearchResult(SearchResult $searchResult) { |
254
|
|
|
foreach ($searchResult->getDocuments() as $document) { |
255
|
|
|
$document->setLink($document->getSource()); |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
|
260
|
|
|
} |