Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[19] limit constructing of result objects in file search #26073

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions lib/private/Search/Provider/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,31 @@
namespace OC\Search\Provider;

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

/**
* 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
*
* @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);
$results = [];
if ($limit !== null) {
$files = array_slice($files, $offset, $offset + $limit);
}
// edit results
foreach ($files as $fileData) {
// skip versions
Expand Down Expand Up @@ -75,4 +86,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);
}
}
}