Completed
Push — master ( 93ddc0...985e16 )
by Maxence
04:27
created

FilesProvider::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Files_FullTextSearch - Index the content of your files
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\Files_FullTextSearch\Provider;
28
29
use OCA\Files_FullTextSearch\AppInfo\Application;
30
use OCA\Files_FullTextSearch\Model\FilesDocument;
31
use OCA\Files_FullTextSearch\Service\ConfigService;
32
use OCA\Files_FullTextSearch\Service\ElasticSearchService;
33
use OCA\Files_FullTextSearch\Service\FilesService;
34
use OCA\Files_FullTextSearch\Service\MiscService;
35
use OCA\Files_FullTextSearch\Service\SearchService;
36
use OCA\FullTextSearch\Exceptions\InterruptException;
37
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
38
use OCA\FullTextSearch\IFullTextSearchPlatform;
39
use OCA\FullTextSearch\IFullTextSearchProvider;
40
use OCA\FullTextSearch\Model\Index;
41
use OCA\FullTextSearch\Model\IndexDocument;
42
use OCA\FullTextSearch\Model\Runner;
43
use OCA\FullTextSearch\Model\SearchRequest;
44
use OCA\FullTextSearch\Model\SearchResult;
45
use OCP\AppFramework\QueryException;
46
use OCP\Files\InvalidPathException;
47
use OCP\Files\NotFoundException;
48
use OCP\Files\NotPermittedException;
49
50
class FilesProvider implements IFullTextSearchProvider {
51
52
53
	const FILES_PROVIDER_ID = 'files';
54
55
	/** @var ConfigService */
56
	private $configService;
57
58
	/** @var FilesService */
59
	private $filesService;
60
61
	/** @var SearchService */
62
	private $searchService;
63
64
	/** @var ElasticSearchService */
65
	private $elasticSearchService;
66
67
	/** @var MiscService */
68
	private $miscService;
69
70
71
	/** @var Runner */
72
	private $runner;
73
74
75
	/**
76
	 * return unique id of the provider
77
	 */
78
	public function getId() {
79
		return self::FILES_PROVIDER_ID;
80
	}
81
82
83
	/**
84
	 * return name of the provider
85
	 */
86
	public function getName() {
87
		return 'Files';
88
	}
89
90
91
	/**
92
	 * @return string
93
	 */
94
	public function getVersion() {
95
		return $this->configService->getAppValue('installed_version');
96
	}
97
98
99
	/**
100
	 * @return array
101
	 */
102
	public function getConfiguration() {
103
		return $this->configService->getConfig();
104
	}
105
106
107
	/**
108
	 * @return string
109
	 */
110
	public function getAppId() {
111
		return Application::APP_NAME;
112
	}
113
114
115
	public function setRunner(Runner $runner) {
116
		$this->runner = $runner;
117
	}
118
119
120
	/**
121
	 * @return string
122
	 */
123
	public function getOptionsTemplate() {
124
		return 'options.panel';
125
	}
126
127
128
	/**
129
	 * called when loading all providers.
130
	 *
131
	 * Loading some containers.
132
	 *
133
	 * @throws QueryException
134
	 */
135
	public function loadProvider() {
136
		$app = new Application();
137
138
		$container = $app->getContainer();
139
		$this->configService = $container->query(ConfigService::class);
140
		$this->filesService = $container->query(FilesService::class);
141
		$this->searchService = $container->query(SearchService::class);
142
		$this->elasticSearchService = $container->query(ElasticSearchService::class);
143
		$this->miscService = $container->query(MiscService::class);
144
	}
145
146
147
	/**
148
	 * returns all indexable document for a user.
149
	 * There is no need to fill the document with content at this point.
150
	 *
151
	 * $platform is provided if the mapping needs to be changed.
152
	 *
153
	 * @param string $userId
154
	 *
155
	 * @return IndexDocument[]
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use FilesDocument[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
156
	 * @throws InterruptException
157
	 * @throws TickDoesNotExistException
158
	 * @throws InvalidPathException
159
	 * @throws NotFoundException
160
	 */
161
	public function generateIndexableDocuments($userId) {
162
		$files = $this->filesService->getFilesFromUser($this->runner, $userId);
163
164
		return $files;
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[]
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use FilesDocument[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
175
	 */
176
	public function fillIndexDocuments($chunk) {
177
178
		/** @var FilesDocument[] $chunk */
179
		$result = $this->filesService->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->filesService->isDocumentUpToDate($document);
192
	}
193
194
195
	/**
196
	 * @param Index $index
197
	 *
198
	 * @return IndexDocument|null
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use FilesDocument|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
199
	 * @throws InvalidPathException
200
	 * @throws NotFoundException
201
	 * @throws NotPermittedException
202
	 */
203
	public function updateDocument(Index $index) {
204
		return $this->filesService->updateDocument($index);
205
	}
206
207
208
	/**
209
	 * @param IFullTextSearchPlatform $platform
210
	 */
211
	public function onInitializingIndex(IFullTextSearchPlatform $platform) {
212
		$this->elasticSearchService->onInitializingIndex($platform);
213
	}
214
215
	/**
216
	 * @param IFullTextSearchPlatform $platform
217
	 * @param array $arr
218
	 */
219
	public function onIndexingDocument(IFullTextSearchPlatform $platform, &$arr) {
220
		$this->elasticSearchService->onIndexingDocument($platform, $arr);
221
	}
222
223
	/**
224
	 * @param IFullTextSearchPlatform $platform
225
	 */
226
	public function onResettingIndex(IFullTextSearchPlatform $platform) {
227
		$this->elasticSearchService->onResettingIndex($platform);
228
	}
229
230
	/**
231
	 * @param IFullTextSearchPlatform $platform
232
	 * @param SearchRequest $request
233
	 * @param array $arr
234
	 */
235
	public function onSearchingQuery(
236
		IFullTextSearchPlatform $platform, SearchRequest $request, &$arr
237
	) {
238
		$this->elasticSearchService->onSearchingQuery($platform, $request, $arr);
239
	}
240
241
242
	/**
243
	 * not used yet
244
	 */
245
	public function unloadProvider() {
246
	}
247
248
249
	/**
250
	 * before a search, improve the request
251
	 *
252
	 * @param SearchRequest $request
253
	 */
254
	public function improveSearchRequest(SearchRequest $request) {
255
		$this->searchService->improveSearchRequest($request);
256
	}
257
258
259
	/**
260
	 * after a search, improve results
261
	 *
262
	 * @param SearchResult $searchResult
263
	 *
264
	 * @throws InvalidPathException
265
	 * @throws NotFoundException
266
	 */
267
	public function improveSearchResult(SearchResult $searchResult) {
268
269
		// TODO - avoid ->setInfo()
270
		foreach ($searchResult->getDocuments() as $document) {
271
			$this->filesService->setDocumentInfo($document);
272
			$this->filesService->setDocumentTitle($document);
273
			$this->filesService->setDocumentLink($document);
274
			$this->filesService->setDocumentMore($document);
275
		}
276
	}
277
278
279
}