Merge pull request #26073 from nextcloud/search-file-limit-results-19

[19] limit constructing of result objects in file search
This commit is contained in:
Morris Jobke 2021-03-18 13:54:10 +01:00 committed by GitHub
commit eb749b3802
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 3 deletions

View File

@ -29,20 +29,31 @@
namespace OC\Search\Provider; namespace OC\Search\Provider;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OCP\Search\PagedProvider;
/** /**
* Provide search results from the 'files' app * Provide search results from the 'files' app
*/ */
class File extends \OCP\Search\Provider { class File extends PagedProvider {
/** /**
* Search for files and folders matching the given query * Search for files and folders matching the given query
*
* @param string $query * @param string $query
* @return \OCP\Search\Result * @param int|null $limit
* @param int|null $offset
* @return \OCP\Search\Result[]
*/ */
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); $files = Filesystem::search($query);
$results = []; $results = [];
if ($limit !== null) {
$files = array_slice($files, $offset, $offset + $limit);
}
// edit results // edit results
foreach ($files as $fileData) { foreach ($files as $fileData) {
// skip versions // skip versions
@ -75,4 +86,12 @@ class File extends \OCP\Search\Provider {
// return // return
return $results; return $results;
} }
public function searchPaged($query, $page, $size) {
if ($size === 0) {
return $this->search($query);
} else {
return $this->search($query, $size, ($page - 1) * $size);
}
}
} }