Completed
Push — master ( dba968...9e87bf )
by Maxence
02:27
created

TestProvider::fillIndexDocument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * FullTextSearch - Full text search framework for Nextcloud
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
28
namespace OCA\FullTextSearch\Provider;
29
30
use OCA\FullTextSearch\AppInfo\Application;
31
use OCA\FullTextSearch\IFullTextSearchPlatform;
32
use OCA\FullTextSearch\IFullTextSearchProvider;
33
use OCA\FullTextSearch\Model\Index;
34
use OCA\FullTextSearch\Model\IndexDocument;
35
use OCA\FullTextSearch\Model\IndexOptions;
36
use OCA\FullTextSearch\Model\Runner;
37
use OCA\FullTextSearch\Model\SearchRequest;
38
use OCA\FullTextSearch\Model\SearchResult;
39
use OCA\FullTextSearch\Service\ConfigService;
40
use OCA\FullTextSearch\Service\MiscService;
41
use OCA\FullTextSearch\Service\TestService;
42
43
class TestProvider implements IFullTextSearchProvider {
44
45
46
	const TEST_PROVIDER_ID = 'test_provider';
47
48
	/** @var ConfigService */
49
	private $configService;
50
51
	/** @var TestService */
52
	private $testService;
53
54
	/** @var MiscService */
55
	private $miscService;
56
57
	/** @var Runner */
58
	private $runner;
59
60
	/** @var IndexOptions */
61
	private $indexOptions;
62
63
64
	/**
65
	 * TestProvider constructor.
66
	 *
67
	 * @param ConfigService $configService
68
	 * @param TestService $testService
69
	 * @param MiscService $miscService
70
	 */
71
	public function __construct(
72
		ConfigService $configService, TestService $testService, MiscService $miscService
73
	) {
74
		$this->configService = $configService;
75
		$this->testService = $testService;
76
		$this->miscService = $miscService;
77
78
		$this->indexOptions = new IndexOptions();
79
	}
80
81
82
	/**
83
	 * return unique id of the provider
84
	 */
85
	public function getId() {
86
		return self::TEST_PROVIDER_ID;
87
	}
88
89
90
	/**
91
	 * return name of the provider
92
	 */
93
	public function getName() {
94
		return 'Test Provider';
95
	}
96
97
98
	/**
99
	 * @return string
100
	 */
101
	public function getVersion() {
102
		return $this->configService->getAppValue('installed_version');
103
	}
104
105
106
	/**
107
	 * @return array
108
	 */
109
	public function getConfiguration() {
110
		return $this->configService->getConfig();
111
	}
112
113
114
	/**
115
	 * @return string
116
	 */
117
	public function getAppId() {
118
		return Application::APP_NAME;
119
	}
120
121
122
	public function setRunner(Runner $runner) {
123
		$this->runner = $runner;
124
	}
125
126
127
	/**
128
	 * @param IndexOptions $options
129
	 */
130
	public function setIndexOptions($options) {
131
		$this->indexOptions = $options;
132
	}
133
134
135
	/**
136
	 * @return array
137
	 */
138
	public function getOptionsTemplate() {
139
		return [];
140
	}
141
142
143
	/**
144
	 * called when loading all providers.
145
	 *
146
	 * Loading some containers.
147
	 */
148
	public function loadProvider() {
149
	}
150
151
152
	/**
153
	 * returns all indexable document for a user.
154
	 * There is no need to fill the document with content at this point.
155
	 *
156
	 * $platform is provided if the mapping needs to be changed.
157
	 *
158
	 * @param string $userId
159
	 *
160
	 * @return IndexDocument[]
161
	 */
162
	public function generateIndexableDocuments($userId) {
163
		$result = [];
164
165
		$result[] = $this->testService->generateIndexDocumentContentLicense($this->indexOptions);
166
		$result[] = $this->testService->generateIndexDocumentSimple($this->indexOptions);
167
168
//		$result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX3);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
169
170
		return $result;
171
	}
172
173
174
	/**
175
	 * generate documents prior to the indexing.
176
	 * throw NoResultException if no more result
177
	 *
178
	 * @param IndexDocument[] $chunk
179
	 *
180
	 * @deprecated
181
	 * @return IndexDocument[]
182
	 */
183
	public function fillIndexDocuments($chunk) {
184
		return $chunk;
185
	}
186
187
188
	/**
189
	 * generate documents prior to the indexing.
190
	 *
191
	 * @param IndexDocument $document
192
	 */
193
	public function fillIndexDocument(IndexDocument $document) {
0 ignored issues
show
Unused Code introduced by
The parameter $document is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
194
	}
195
196
197
	/**
198
	 * @param IndexDocument $document
199
	 *
200
	 * @return bool
201
	 */
202
	public function isDocumentUpToDate($document) {
203
		return false;
204
	}
205
206
207
	/**
208
	 * @param Index $index
209
	 *
210
	 * @return IndexDocument|null
211
	 */
212
	public function updateDocument(Index $index) {
213
		return null;
214
	}
215
216
217
	/**
218
	 * @param IFullTextSearchPlatform $platform
219
	 */
220
	public function onInitializingIndex(IFullTextSearchPlatform $platform) {
221
	}
222
223
224
	/**
225
	 * @param IFullTextSearchPlatform $platform
226
	 */
227
	public function onResettingIndex(IFullTextSearchPlatform $platform) {
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
	}
245
246
247
	/**
248
	 * after a search, improve results
249
	 *
250
	 * @param SearchResult $searchResult
251
	 */
252
	public function improveSearchResult(SearchResult $searchResult) {
253
	}
254
255
256
}