Skip to content

Commit 1bae014

Browse files
Implement unified search for Files
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent e0dbfe5 commit 1bae014

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

apps/files/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
4848
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
4949
'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
50+
'OCA\\Files\\Search\\FilesSearchProvider' => $baseDir . '/../lib/Search/FilesSearchProvider.php',
51+
'OCA\\Files\\Search\\FilesSearchResultEntry' => $baseDir . '/../lib/Search/FilesSearchResultEntry.php',
5052
'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php',
5153
'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php',
5254
'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php',

apps/files/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class ComposerStaticInitFiles
6262
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
6363
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
6464
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
65+
'OCA\\Files\\Search\\FilesSearchProvider' => __DIR__ . '/..' . '/../lib/Search/FilesSearchProvider.php',
66+
'OCA\\Files\\Search\\FilesSearchResultEntry' => __DIR__ . '/..' . '/../lib/Search/FilesSearchResultEntry.php',
6567
'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php',
6668
'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php',
6769
'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php',

apps/files/lib/AppInfo/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
4444
use OCA\Files\Listener\LoadSidebarListener;
4545
use OCA\Files\Notification\Notifier;
46+
use OCA\Files\Search\FilesSearchProvider;
4647
use OCA\Files\Service\TagService;
4748
use OCP\AppFramework\App;
4849
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -103,6 +104,8 @@ public function register(IRegistrationContext $context): void {
103104

104105
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
105106
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
107+
108+
$context->registerSearchProvider(FilesSearchProvider::class);
106109
}
107110

108111
public function boot(IBootContext $context): void {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
7+
*
8+
* @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
9+
*
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+
namespace OCA\Files\Search;
27+
28+
use OCP\IL10N;
29+
use OCP\IUser;
30+
use OCP\Search\IProvider;
31+
use OCP\Search\ISearchQuery;
32+
use OCP\Search\SearchResult;
33+
34+
class FilesSearchProvider implements IProvider {
35+
36+
/** @var IL10N */
37+
private $l10n;
38+
39+
public function __construct(IL10N $l10n) {
40+
$this->l10n = $l10n;
41+
}
42+
43+
public function search(IUser $user, ISearchQuery $query): SearchResult {
44+
return SearchResult::complete(
45+
$this->l10n->t('Files'),
46+
[
47+
new FilesSearchResultEntry(
48+
"path/to/icon.png",
49+
"cute cats.jpg",
50+
"/Cats",
51+
"/f/21156"
52+
),
53+
new FilesSearchResultEntry(
54+
"path/to/icon.png",
55+
"cat 1.jpg",
56+
"/Cats",
57+
"/f/21192"
58+
),
59+
new FilesSearchResultEntry(
60+
"path/to/icon.png",
61+
"cat 2.jpg",
62+
"/Cats",
63+
"/f/25942"
64+
),
65+
]
66+
);
67+
}
68+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
7+
*
8+
* @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
9+
*
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+
namespace OCA\Files\Search;
27+
28+
use OCP\Search\ASearchResultEntry;
29+
30+
class FilesSearchResultEntry extends ASearchResultEntry {
31+
public function __construct(string $thumbnailUrl,
32+
string $filename,
33+
string $path,
34+
string $url) {
35+
parent::__construct($thumbnailUrl, $filename, $path, $url);
36+
}
37+
}

0 commit comments

Comments
 (0)