diff options
author | Robin Appelman <robin@icewind.nl> | 2017-03-08 15:17:39 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-03-08 16:30:55 +0100 |
commit | e61606a767cd6e2c28e3897e7e913e39371078e5 (patch) | |
tree | b2d0cf869dae5f4cce698ca647f827aab178aaa0 /lib/private/Files/Cache | |
parent | 2a8e922d67a1246e101f926f1b0ab287db71929e (diff) | |
download | nextcloud-server-e61606a767cd6e2c28e3897e7e913e39371078e5.tar.gz nextcloud-server-e61606a767cd6e2c28e3897e7e913e39371078e5.zip |
Allow searching for favorites
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Cache')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 21 | ||||
-rw-r--r-- | lib/private/Files/Cache/QuerySearchHelper.php | 32 |
2 files changed, 47 insertions, 6 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index b0527d801d6..c3ac0f8444f 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -645,9 +645,22 @@ class Cache implements ICache { $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $query = $builder->select(['fileid', 'storage', 'path', 'parent', 'name', 'mimetype', 'mimepart', 'size', 'mtime', 'storage_mtime', 'encrypted', 'etag', 'permissions', 'checksum']) - ->from('filecache') - ->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId()))) - ->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation())); + ->from('filecache', 'file'); + + $query->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId()))); + + if ($this->querySearchHelper->shouldJoinTags($searchQuery->getSearchOperation())) { + $query + ->innerJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid')) + ->innerJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX( + $builder->expr()->eq('tagmap.type', 'tag.type'), + $builder->expr()->eq('tagmap.categoryid', 'tag.id') + )) + ->andWhere($builder->expr()->eq('tag.type', $builder->createNamedParameter('files'))) + ->andWhere($builder->expr()->eq('tag.uid', $builder->createNamedParameter($searchQuery->getUser()->getUID()))); + } + + $query->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation())); if ($searchQuery->getLimit()) { $query->setMaxResults($searchQuery->getLimit()); @@ -660,7 +673,7 @@ class Cache implements ICache { return $this->searchResultToCacheEntries($result); } - /** + /** * Search for files by tag of a given users. * * Note that every user can tag files differently. diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 931f258ec5b..7d8098f0efa 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -49,6 +49,8 @@ class QuerySearchHelper { ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lt' ]; + const TAG_FAVORITE = '_$!<Favorite>!$_'; + /** @var IMimeTypeLoader */ private $mimetypeLoader; @@ -61,6 +63,23 @@ class QuerySearchHelper { $this->mimetypeLoader = $mimetypeLoader; } + /** + * Whether or not the tag tables should be joined to complete the search + * + * @param ISearchOperator $operator + * @return boolean + */ + public function shouldJoinTags(ISearchOperator $operator) { + if ($operator instanceof ISearchBinaryOperator) { + return array_reduce($operator->getArguments(), function ($shouldJoin, ISearchOperator $operator) { + return $shouldJoin || $this->shouldJoinTags($operator); + }, false); + } else if ($operator instanceof ISearchComparison) { + return $operator->getField() === 'tagname' || $operator->getField() === 'favorite'; + } + return false; + } + public function searchOperatorToDBExpr(IQueryBuilder $builder, ISearchOperator $operator) { $expr = $builder->expr(); if ($operator instanceof ISearchBinaryOperator) { @@ -116,6 +135,11 @@ class QuerySearchHelper { throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); } } + } else if ($field === 'favorite') { + $field = 'tag.category'; + $value = self::TAG_FAVORITE; + } else if ($field === 'tagname') { + $field = 'tag.category'; } return [$field, $value, $type]; } @@ -125,13 +149,17 @@ class QuerySearchHelper { 'mimetype' => 'string', 'mtime' => 'integer', 'name' => 'string', - 'size' => 'integer' + 'size' => 'integer', + 'tagname' => 'string', + 'favorite' => 'boolean' ]; $comparisons = [ 'mimetype' => ['eq', 'like'], 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], 'name' => ['eq', 'like'], - 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'] + 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'], + 'tagname' => ['eq', 'like'], + 'favorite' => ['eq'], ]; if (!isset($types[$operator->getField()])) { |