|
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
|
|
|
/** |
|
112
|
|
|
* @param Runner $runner |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setRunner(Runner $runner) { |
|
115
|
|
|
$this->runner = $runner; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return array |
|
|
|
|
|
|
121
|
|
|
*/ |
|
122
|
|
|
public function getOptionsTemplate() { |
|
123
|
|
|
return [ |
|
124
|
|
|
'navigation' => [ |
|
125
|
|
|
'icon' => 'icon-bookmarks', |
|
126
|
|
|
'css' => 'navigate' |
|
127
|
|
|
] |
|
128
|
|
|
]; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* called when loading all providers. |
|
134
|
|
|
* |
|
135
|
|
|
* Loading some containers. |
|
136
|
|
|
* |
|
137
|
|
|
* @throws QueryException |
|
138
|
|
|
*/ |
|
139
|
|
|
public function loadProvider() { |
|
140
|
|
|
$app = new Application(); |
|
141
|
|
|
|
|
142
|
|
|
$container = $app->getContainer(); |
|
143
|
|
|
$this->configService = $container->query(ConfigService::class); |
|
144
|
|
|
$this->bookmarksService = $container->query(BookmarksService::class); |
|
145
|
|
|
$this->searchService = $container->query(SearchService::class); |
|
146
|
|
|
$this->elasticSearchService = $container->query(ElasticSearchService::class); |
|
147
|
|
|
$this->miscService = $container->query(MiscService::class); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* returns all indexable document for a user. |
|
153
|
|
|
* There is no need to fill the document with content at this point. |
|
154
|
|
|
* |
|
155
|
|
|
* $platform is provided if the mapping needs to be changed. |
|
156
|
|
|
* |
|
157
|
|
|
* @param string $userId |
|
158
|
|
|
* |
|
159
|
|
|
* @return BookmarksDocument[] |
|
160
|
|
|
*/ |
|
161
|
|
|
public function generateIndexableDocuments($userId) { |
|
162
|
|
|
$bookmarks = $this->bookmarksService->getBookmarksFromUser($this->runner, $userId); |
|
163
|
|
|
|
|
164
|
|
|
return $bookmarks; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* generate documents prior to the indexing. |
|
170
|
|
|
* throw NoResultException if no more result |
|
171
|
|
|
* |
|
172
|
|
|
* @param IndexDocument[] $chunk |
|
173
|
|
|
* |
|
174
|
|
|
* @return IndexDocument[] |
|
175
|
|
|
*/ |
|
176
|
|
|
public function fillIndexDocuments($chunk) { |
|
177
|
|
|
|
|
178
|
|
|
/** @var BookmarksDocument[] $chunk */ |
|
179
|
|
|
$result = $this->bookmarksService->generateDocuments($chunk); |
|
180
|
|
|
|
|
181
|
|
|
return $result; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @param IndexDocument $document |
|
187
|
|
|
* |
|
188
|
|
|
* @return bool |
|
189
|
|
|
*/ |
|
190
|
|
|
public function isDocumentUpToDate($document) { |
|
191
|
|
|
return $this->bookmarksService->isDocumentUpToDate($document); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param Index $index |
|
197
|
|
|
* |
|
198
|
|
|
* @return BookmarksDocument|null |
|
199
|
|
|
*/ |
|
200
|
|
|
public function updateDocument(Index $index) { |
|
201
|
|
|
return $this->bookmarksService->updateDocument($index); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @param IFullTextSearchPlatform $platform |
|
207
|
|
|
*/ |
|
208
|
|
|
public function onInitializingIndex(IFullTextSearchPlatform $platform) { |
|
209
|
|
|
$this->elasticSearchService->onInitializingIndex($platform); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @param IFullTextSearchPlatform $platform |
|
215
|
|
|
*/ |
|
216
|
|
|
public function onResettingIndex(IFullTextSearchPlatform $platform) { |
|
217
|
|
|
$this->elasticSearchService->onResettingIndex($platform); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* not used yet |
|
223
|
|
|
*/ |
|
224
|
|
|
public function unloadProvider() { |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* before a search, improve the request |
|
230
|
|
|
* |
|
231
|
|
|
* @param SearchRequest $request |
|
232
|
|
|
*/ |
|
233
|
|
|
public function improveSearchRequest(SearchRequest $request) { |
|
234
|
|
|
$this->searchService->improveSearchRequest($request); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* after a search, improve results |
|
240
|
|
|
* |
|
241
|
|
|
* @param SearchResult $searchResult |
|
242
|
|
|
*/ |
|
243
|
|
|
public function improveSearchResult(SearchResult $searchResult) { |
|
244
|
|
|
foreach ($searchResult->getDocuments() as $document) { |
|
245
|
|
|
$document->setLink($document->getSource()); |
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
} |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.