|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Andrew Brown <[email protected]> |
|
6
|
|
|
* @author Bart Visscher <[email protected]> |
|
7
|
|
|
* @author Christoph Wurst <[email protected]> |
|
8
|
|
|
* @author Jakob Sack <[email protected]> |
|
9
|
|
|
* @author John Molakvoæ (skjnldsv) <[email protected]> |
|
10
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
11
|
|
|
* @author Morris Jobke <[email protected]> |
|
12
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
13
|
|
|
* |
|
14
|
|
|
* @license AGPL-3.0 |
|
15
|
|
|
* |
|
16
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
17
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* as published by the Free Software Foundation. |
|
19
|
|
|
* |
|
20
|
|
|
* This program is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU Affero General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
namespace OC\Search\Provider; |
|
31
|
|
|
|
|
32
|
|
|
use OC\Files\Filesystem; |
|
33
|
|
|
use OCP\Search\PagedProvider; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Provide search results from the 'files' app |
|
37
|
|
|
* @deprecated 20.0.0 |
|
38
|
|
|
*/ |
|
39
|
|
|
class File extends PagedProvider { |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Search for files and folders matching the given query |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $query |
|
45
|
|
|
* @param int|null $limit |
|
46
|
|
|
* @param int|null $offset |
|
47
|
|
|
* @return \OCP\Search\Result[] |
|
48
|
|
|
* @deprecated 20.0.0 |
|
49
|
|
|
*/ |
|
50
|
|
|
public function search($query, int $limit = null, int $offset = null) { |
|
51
|
|
|
if ($offset === null) { |
|
52
|
|
|
$offset = 0; |
|
53
|
|
|
} |
|
54
|
|
|
\OC_Util::setupFS(); |
|
55
|
|
|
$files = Filesystem::search($query); |
|
56
|
|
|
$results = []; |
|
57
|
|
|
if ($limit !== null) { |
|
58
|
|
|
$files = array_slice($files, $offset, $offset + $limit); |
|
59
|
|
|
} |
|
60
|
|
|
// edit results |
|
61
|
|
|
foreach ($files as $fileData) { |
|
62
|
|
|
// skip versions |
|
63
|
|
|
if (strpos($fileData['path'], '_versions') === 0) { |
|
64
|
|
|
continue; |
|
65
|
|
|
} |
|
66
|
|
|
// skip top-level folder |
|
67
|
|
|
if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
68
|
|
|
continue; |
|
69
|
|
|
} |
|
70
|
|
|
// create audio result |
|
71
|
|
|
if ($fileData['mimepart'] === 'audio') { |
|
72
|
|
|
$result = new \OC\Search\Result\Audio($fileData); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
// create image result |
|
75
|
|
|
elseif ($fileData['mimepart'] === 'image') { |
|
76
|
|
|
$result = new \OC\Search\Result\Image($fileData); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
// create folder result |
|
79
|
|
|
elseif ($fileData['mimetype'] === 'httpd/unix-directory') { |
|
80
|
|
|
$result = new \OC\Search\Result\Folder($fileData); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
// or create file result |
|
83
|
|
|
else { |
|
84
|
|
|
$result = new \OC\Search\Result\File($fileData); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
// add to results |
|
87
|
|
|
$results[] = $result; |
|
88
|
|
|
} |
|
89
|
|
|
// return |
|
90
|
|
|
return $results; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function searchPaged($query, $page, $size) { |
|
94
|
|
|
if ($size === 0) { |
|
95
|
|
|
return $this->search($query); |
|
96
|
|
|
} else { |
|
97
|
|
|
return $this->search($query, $size, ($page - 1) * $size); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|