diff options
Diffstat (limited to 'lib/private/search.php')
-rw-r--r-- | lib/private/search.php | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/private/search.php b/lib/private/search.php index 8f04aa8360b..a29a4762b68 100644 --- a/lib/private/search.php +++ b/lib/private/search.php @@ -21,6 +21,7 @@ */ namespace OC; +use OCP\Search\PagedProvider; use OCP\Search\Provider; use OCP\ISearch; @@ -39,12 +40,38 @@ class Search implements ISearch { * @return array An array of OC\Search\Result's */ public function search($query, array $inApps = array()) { + // old apps might assume they get all results, so we set size 0 + return $this->searchPaged($query, $inApps, 1, 0); + } + + /** + * Search all providers for $query + * @param string $query + * @param string[] $inApps optionally limit results to the given apps + * @param int $page pages start at page 1 + * @param int $size, 0 = all + * @return array An array of OC\Search\Result's + */ + public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { $this->initProviders(); $results = array(); foreach($this->providers as $provider) { /** @var $provider Provider */ - if ($provider->providesResultsFor($inApps)) { - $results = array_merge($results, $provider->search($query)); + if ( ! $provider->providesResultsFor($inApps) ) { + continue; + } + if ($provider instanceof PagedProvider) { + $results = array_merge($results, $provider->searchPaged($query, $page, $size)); + } else if ($provider instanceof Provider) { + $providerResults = $provider->search($query); + if ($size > 0) { + $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); + $results = array_merge($results, $slicedResults); + } else { + $results = array_merge($results, $providerResults); + } + } else { + \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); } } return $results; |