summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-03-19 14:47:30 +0100
committerRobin Appelman <robin@icewind.nl>2021-03-19 16:08:01 +0100
commitb38618c8139a8017590ea59064184307a93f9808 (patch)
tree2b804f646f019912f4d6ce7e4dd8f4a2291d15b0
parenta0fb6d251893fcb4817853ff8636a61bbae088ee (diff)
downloadnextcloud-server-b38618c8139a8017590ea59064184307a93f9808.tar.gz
nextcloud-server-b38618c8139a8017590ea59064184307a93f9808.zip
use node search api for legacy file search endpoint
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--core/Controller/SearchController.php1
-rw-r--r--lib/private/Search/Provider/File.php48
-rw-r--r--lib/private/Search/Result/File.php7
3 files changed, 33 insertions, 23 deletions
diff --git a/core/Controller/SearchController.php b/core/Controller/SearchController.php
index 72633630dad..42439e9ceb9 100644
--- a/core/Controller/SearchController.php
+++ b/core/Controller/SearchController.php
@@ -55,6 +55,7 @@ class SearchController extends Controller {
/**
* @NoAdminRequired
+ * @NoCSRFRequired
*/
public function search(string $query, array $inApps = [], int $page = 1, int $size = 30): JSONResponse {
$results = $this->searcher->searchPaged($query, $inApps, $page, $size);
diff --git a/lib/private/Search/Provider/File.php b/lib/private/Search/Provider/File.php
index 4125b1f7d70..d42d57b8003 100644
--- a/lib/private/Search/Provider/File.php
+++ b/lib/private/Search/Provider/File.php
@@ -29,7 +29,14 @@
namespace OC\Search\Provider;
-use OC\Files\Filesystem;
+use OC\Files\Search\SearchComparison;
+use OC\Files\Search\SearchOrder;
+use OC\Files\Search\SearchQuery;
+use OCP\Files\FileInfo;
+use OCP\Files\IRootFolder;
+use OCP\Files\Search\ISearchComparison;
+use OCP\Files\Search\ISearchOrder;
+use OCP\IUserSession;
use OCP\Search\PagedProvider;
/**
@@ -48,35 +55,38 @@ class File extends PagedProvider {
* @deprecated 20.0.0
*/
public function search($query, int $limit = null, int $offset = null) {
- if ($offset === null) {
- $offset = 0;
+ /** @var IRootFolder $rootFolder */
+ $rootFolder = \OC::$server->query(IRootFolder::class);
+ /** @var IUserSession $userSession */
+ $userSession = \OC::$server->query(IUserSession::class);
+ $user = $userSession->getUser();
+ if (!$user) {
+ return [];
}
- \OC_Util::setupFS();
- $files = Filesystem::search($query);
+ $userFolder = $rootFolder->getUserFolder($user->getUID());
+ $fileQuery = new SearchQuery(
+ new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%' . $query . '%'),
+ (int)$limit,
+ (int)$offset,
+ [
+ new SearchOrder(ISearchOrder::DIRECTION_DESCENDING, 'mtime'),
+ ],
+ $user
+ );
+ $files = $userFolder->search($fileQuery);
$results = [];
- if ($limit !== null) {
- $files = array_slice($files, $offset, $offset + $limit);
- }
// edit results
foreach ($files as $fileData) {
- // skip versions
- if (strpos($fileData['path'], '_versions') === 0) {
- continue;
- }
- // skip top-level folder
- if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
- continue;
- }
// create audio result
- if ($fileData['mimepart'] === 'audio') {
+ if ($fileData->getMimePart() === 'audio') {
$result = new \OC\Search\Result\Audio($fileData);
}
// create image result
- elseif ($fileData['mimepart'] === 'image') {
+ elseif ($fileData->getMimePart() === 'image') {
$result = new \OC\Search\Result\Image($fileData);
}
// create folder result
- elseif ($fileData['mimetype'] === 'httpd/unix-directory') {
+ elseif ($fileData->getMimetype() === FileInfo::MIMETYPE_FOLDER) {
$result = new \OC\Search\Result\Folder($fileData);
}
// or create file result
diff --git a/lib/private/Search/Result/File.php b/lib/private/Search/Result/File.php
index 33e1e97f471..c3b0c4e3751 100644
--- a/lib/private/Search/Result/File.php
+++ b/lib/private/Search/Result/File.php
@@ -97,14 +97,13 @@ class File extends \OCP\Search\Result {
public function __construct(FileInfo $data) {
$path = $this->getRelativePath($data->getPath());
- $info = pathinfo($path);
$this->id = $data->getId();
- $this->name = $info['basename'];
+ $this->name = $data->getName();
$this->link = \OC::$server->getURLGenerator()->linkToRoute(
'files.view.index',
[
- 'dir' => $info['dirname'],
- 'scrollto' => $info['basename'],
+ 'dir' => dirname($path),
+ 'scrollto' => $data->getName(),
]
);
$this->permissions = $data->getPermissions();