From e198dc1b200f3ade93498e0ea7b468c87d46748a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 4 May 2021 19:06:02 +0200 Subject: rework search api to allow searching on multiple caches at once Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Wrapper/CacheWrapper.php | 50 ++++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'lib/private/Files/Cache/Wrapper/CacheWrapper.php') diff --git a/lib/private/Files/Cache/Wrapper/CacheWrapper.php b/lib/private/Files/Cache/Wrapper/CacheWrapper.php index 01fbdd3bf42..edda332af67 100644 --- a/lib/private/Files/Cache/Wrapper/CacheWrapper.php +++ b/lib/private/Files/Cache/Wrapper/CacheWrapper.php @@ -30,6 +30,8 @@ namespace OC\Files\Cache\Wrapper; use OC\Files\Cache\Cache; +use OC\Files\Cache\QuerySearchHelper; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Search\ISearchQuery; @@ -45,6 +47,14 @@ class CacheWrapper extends Cache { */ public function __construct($cache) { $this->cache = $cache; + $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); + $this->connection = \OC::$server->getDatabaseConnection(); + $this->querySearchHelper = new QuerySearchHelper( + $this->mimetypeLoader, + $this->connection, + \OC::$server->getSystemConfig(), + \OC::$server->getLogger() + ); } protected function getCache() { @@ -215,31 +225,8 @@ class CacheWrapper extends Cache { return $this->getCache()->getStatus($file); } - /** - * search for files matching $pattern - * - * @param string $pattern - * @return ICacheEntry[] an array of file data - */ - public function search($pattern) { - $results = $this->getCache()->search($pattern); - return array_map([$this, 'formatCacheEntry'], $results); - } - - /** - * search for files by mimetype - * - * @param string $mimetype - * @return ICacheEntry[] - */ - public function searchByMime($mimetype) { - $results = $this->getCache()->searchByMime($mimetype); - return array_map([$this, 'formatCacheEntry'], $results); - } - - public function searchQuery(ISearchQuery $query) { - $results = $this->getCache()->searchQuery($query); - return array_map([$this, 'formatCacheEntry'], $results); + public function searchQuery(ISearchQuery $searchQuery) { + return $this->querySearchHelper->searchInCaches($searchQuery, [$this]); } /** @@ -321,4 +308,17 @@ class CacheWrapper extends Cache { public static function getById($id) { return parent::getById($id); } + + public function getQueryFilterForStorage(IQueryBuilder $builder) { + return $this->getCache()->getQueryFilterForStorage($builder); + } + + public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry { + $rawEntry = $this->getCache()->getCacheEntryFromSearchResult($rawEntry); + if ($rawEntry) { + return $this->formatCacheEntry(clone $rawEntry); + } + + return null; + } } -- cgit v1.2.3