Skip to content

Commit

Permalink
Merge pull request #26049 from nextcloud/search-file-limit-results
Browse files Browse the repository at this point in the history
limit constructing of result objects in file search
  • Loading branch information
rullzer authored Mar 12, 2021
2 parents 7ac6eee + b62ee57 commit bf39adb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/files/lib/Search/FilesSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
// Make sure we setup the users filesystem
$this->rootFolder->getUserFolder($user->getUID());

return SearchResult::complete(
return SearchResult::paginated(
$this->l10n->t('Files'),
array_map(function (FileResult $result) {
// Generate thumbnail url
Expand All @@ -121,7 +121,8 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$searchResultEntry->addAttribute('fileId', (string)$result->id);
$searchResultEntry->addAttribute('path', $result->path);
return $searchResultEntry;
}, $this->fileSearch->search($query->getTerm()))
}, $this->fileSearch->search($query->getTerm(), $query->getLimit(), (int)$query->getCursor())),
$query->getCursor() + $query->getLimit()
);
}

Expand Down
22 changes: 20 additions & 2 deletions lib/private/Search/Provider/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,33 @@
namespace OC\Search\Provider;

use OC\Files\Filesystem;
use OCP\Search\PagedProvider;

/**
* Provide search results from the 'files' app
* @deprecated 20.0.0
*/
class File extends \OCP\Search\Provider {
class File extends PagedProvider {

/**
* Search for files and folders matching the given query
*
* @param string $query
* @param int|null $limit
* @param int|null $offset
* @return \OCP\Search\Result[]
* @deprecated 20.0.0
*/
public function search($query) {
public function search($query, int $limit = null, int $offset = null) {
if ($offset === null) {
$offset = 0;
}
\OC_Util::setupFS();
$files = Filesystem::search($query);
$results = [];
if ($limit !== null) {
$files = array_slice($files, $offset, $offset + $limit);
}
// edit results
foreach ($files as $fileData) {
// skip versions
Expand Down Expand Up @@ -79,4 +89,12 @@ public function search($query) {
// return
return $results;
}

public function searchPaged($query, $page, $size) {
if ($size === 0) {
return $this->search($query);
} else {
return $this->search($query, $size, ($page - 1) * $size);
}
}
}

0 comments on commit bf39adb

Please sign in to comment.