Completed
Push — master ( 43030a...db557c )
by Maxence
06:50 queued 04:30
created

TestProvider   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 203
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 19
lcom 2
cbo 3
dl 0
loc 203
rs 10
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getId() 0 3 1
A getName() 0 3 1
A getVersion() 0 3 1
A getConfiguration() 0 3 1
A getAppId() 0 3 1
A setRunner() 0 3 1
A setIndexOptions() 0 3 1
A getOptionsTemplate() 0 3 1
A loadProvider() 0 2 1
A generateIndexableDocuments() 0 9 1
A fillIndexDocuments() 0 3 1
A isDocumentUpToDate() 0 3 1
A updateDocument() 0 3 1
A onInitializingIndex() 0 2 1
A onResettingIndex() 0 2 1
A unloadProvider() 0 2 1
A improveSearchRequest() 0 2 1
A improveSearchResult() 0 2 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
//		$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...
168
169
		return $result;
170
	}
171
172
173
	/**
174
	 * generate documents prior to the indexing.
175
	 * throw NoResultException if no more result
176
	 *
177
	 * @param IndexDocument[] $chunk
178
	 *
179
	 * @return IndexDocument[]
180
	 */
181
	public function fillIndexDocuments($chunk) {
182
		return $chunk;
183
	}
184
185
186
	/**
187
	 * @param IndexDocument $document
188
	 *
189
	 * @return bool
190
	 */
191
	public function isDocumentUpToDate($document) {
192
		return false;
193
	}
194
195
196
	/**
197
	 * @param Index $index
198
	 *
199
	 * @return IndexDocument|null
200
	 */
201
	public function updateDocument(Index $index) {
202
		return null;
203
	}
204
205
206
	/**
207
	 * @param IFullTextSearchPlatform $platform
208
	 */
209
	public function onInitializingIndex(IFullTextSearchPlatform $platform) {
210
	}
211
212
213
	/**
214
	 * @param IFullTextSearchPlatform $platform
215
	 */
216
	public function onResettingIndex(IFullTextSearchPlatform $platform) {
217
	}
218
219
220
	/**
221
	 * not used yet
222
	 */
223
	public function unloadProvider() {
224
	}
225
226
227
	/**
228
	 * before a search, improve the request
229
	 *
230
	 * @param SearchRequest $request
231
	 */
232
	public function improveSearchRequest(SearchRequest $request) {
233
	}
234
235
236
	/**
237
	 * after a search, improve results
238
	 *
239
	 * @param SearchResult $searchResult
240
	 */
241
	public function improveSearchResult(SearchResult $searchResult) {
242
	}
243
244
245
}