Completed
Push — master ( 5bcd95...9728c3 )
by Maxence
02:00
created

FilesProvider::getVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
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\Http\TemplateResponse;
46
use OCP\AppFramework\QueryException;
47
use OCP\Files\InvalidPathException;
48
use OCP\Files\NotFoundException;
49
use OCP\Files\NotPermittedException;
50
51
class FilesProvider implements IFullTextSearchProvider {
52
53
54
	const FILES_PROVIDER_ID = 'files';
55
56
	/** @var ConfigService */
57
	private $configService;
58
59
	/** @var FilesService */
60
	private $filesService;
61
62
	/** @var SearchService */
63
	private $searchService;
64
65
	/** @var ElasticSearchService */
66
	private $elasticSearchService;
67
68
	/** @var MiscService */
69
	private $miscService;
70
71
72
	/** @var Runner */
73
	private $runner;
74
75
76
	/**
77
	 * return unique id of the provider
78
	 */
79
	public function getId() {
80
		return self::FILES_PROVIDER_ID;
81
	}
82
83
84
	/**
85
	 * return name of the provider
86
	 */
87
	public function getName() {
88
		return 'Files';
89
	}
90
91
92
	/**
93
	 * @return string
94
	 */
95
	public function getVersion() {
96
		return $this->configService->getAppValue('installed_version');
97
	}
98
99
100
	/**
101
	 * @return string
102
	 */
103
	public function getAppId() {
104
		return Application::APP_NAME;
105
	}
106
107
108
	public function setRunner(Runner $runner) {
109
		$this->runner = $runner;
110
	}
111
112
113
	/**
114
	 * @return string
115
	 */
116
	public function getOptionsTemplate() {
117
		return 'options.panel';
118
	}
119
120
121
	/**
122
	 * called when loading all providers.
123
	 *
124
	 * Loading some containers.
125
	 *
126
	 * @throws QueryException
127
	 */
128
	public function loadProvider() {
129
		$app = new Application();
130
131
		$container = $app->getContainer();
132
		$this->configService = $container->query(ConfigService::class);
133
		$this->filesService = $container->query(FilesService::class);
134
		$this->searchService = $container->query(SearchService::class);
135
		$this->elasticSearchService = $container->query(ElasticSearchService::class);
136
		$this->miscService = $container->query(MiscService::class);
137
	}
138
139
140
	/**
141
	 * returns all indexable document for a user.
142
	 * There is no need to fill the document with content at this point.
143
	 *
144
	 * $platform is provided if the mapping needs to be changed.
145
	 *
146
	 * @param string $userId
147
	 *
148
	 * @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...
149
	 * @throws InterruptException
150
	 * @throws TickDoesNotExistException
151
	 * @throws InvalidPathException
152
	 * @throws NotFoundException
153
	 */
154
	public function generateIndexableDocuments($userId) {
155
		$files = $this->filesService->getFilesFromUser($this->runner, $userId);
156
157
		return $files;
158
	}
159
160
161
	/**
162
	 * generate documents prior to the indexing.
163
	 * throw NoResultException if no more result
164
	 *
165
	 * @param IndexDocument[] $chunk
166
	 *
167
	 * @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...
168
	 */
169
	public function fillIndexDocuments($chunk) {
170
171
		/** @var FilesDocument[] $chunk */
172
		$result = $this->filesService->generateDocuments($chunk);
173
174
		return $result;
175
	}
176
177
178
	/**
179
	 * @param IndexDocument $document
180
	 *
181
	 * @return bool
182
	 */
183
	public function isDocumentUpToDate($document) {
184
		return $this->filesService->isDocumentUpToDate($document);
185
	}
186
187
188
	/**
189
	 * @param Index $index
190
	 *
191
	 * @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...
192
	 * @throws InvalidPathException
193
	 * @throws NotFoundException
194
	 * @throws NotPermittedException
195
	 */
196
	public function updateDocument(Index $index) {
197
		return $this->filesService->updateDocument($index);
198
	}
199
200
201
	/**
202
	 * @param IFullTextSearchPlatform $platform
203
	 */
204
	public function onInitializingIndex(IFullTextSearchPlatform $platform) {
205
		$this->elasticSearchService->onInitializingIndex($platform);
206
	}
207
208
	/**
209
	 * @param IFullTextSearchPlatform $platform
210
	 * @param array $arr
211
	 */
212
	public function onIndexingDocument(IFullTextSearchPlatform $platform, &$arr) {
213
		$this->elasticSearchService->onIndexingDocument($platform, $arr);
214
	}
215
216
	/**
217
	 * @param IFullTextSearchPlatform $platform
218
	 */
219
	public function onResettingIndex(IFullTextSearchPlatform $platform) {
220
		$this->elasticSearchService->onResettingIndex($platform);
221
	}
222
223
	/**
224
	 * @param IFullTextSearchPlatform $platform
225
	 * @param SearchRequest $request
226
	 * @param array $arr
227
	 */
228
	public function onSearchingQuery(IFullTextSearchPlatform $platform, SearchRequest $request, &$arr) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 101 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
229
		$this->elasticSearchService->onSearchingQuery($platform, $request, $arr);
230
	}
231
232
233
	/**
234
	 * not used yet
235
	 */
236
	public function unloadProvider() {
237
	}
238
239
240
	/**
241
	 * before a search, improve the request
242
	 *
243
	 * @param SearchRequest $request
244
	 */
245
	public function improveSearchRequest(SearchRequest $request) {
246
		$this->searchService->improveSearchRequest($request);
247
	}
248
249
250
	/**
251
	 * after a search, improve results
252
	 *
253
	 * @param SearchResult $searchResult
254
	 *
255
	 * @throws InvalidPathException
256
	 * @throws NotFoundException
257
	 */
258
	public function improveSearchResult(SearchResult $searchResult) {
259
260
		foreach ($searchResult->getDocuments() as $document) {
261
			$this->filesService->setDocumentInfo($document);
262
			$this->filesService->setDocumentTitle($document);
263
			$this->filesService->setDocumentLink($document);
264
			$this->filesService->setDocumentMore($document);
265
		}
266
	}
267
268
269
}