summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-03-13 00:55:12 -0600
committerGitHub <noreply@github.com>2017-03-13 00:55:12 -0600
commitf7cef9f7024a0f94a36746daee2fe4ef6335bac6 (patch)
tree31d483fc81b5bc47fa70164a6395d8e6e6843ce5 /apps
parent0dd0242d2f82410da66b6d4c6d455a1702779df1 (diff)
parente61606a767cd6e2c28e3897e7e913e39371078e5 (diff)
downloadnextcloud-server-f7cef9f7024a0f94a36746daee2fe4ef6335bac6.tar.gz
nextcloud-server-f7cef9f7024a0f94a36746daee2fe4ef6335bac6.zip
Merge pull request #3772 from nextcloud/favorite-search
Allow searching for favorites
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/Files/FileSearchBackend.php16
-rw-r--r--apps/dav/tests/unit/Files/FileSearchBackendTest.php15
2 files changed, 21 insertions, 10 deletions
diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php
index c429a1727f8..afdb425e8ed 100644
--- a/apps/dav/lib/Files/FileSearchBackend.php
+++ b/apps/dav/lib/Files/FileSearchBackend.php
@@ -28,6 +28,7 @@ use OC\Files\Search\SearchQuery;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\FilesPlugin;
+use OCA\DAV\Connector\Sabre\TagsPlugin;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -114,6 +115,7 @@ class FileSearchBackend implements ISearchBackend {
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
new SearchPropertyDefinition('{DAV:}getlastmodifed', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
+ new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
// select only properties
new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false),
@@ -178,7 +180,7 @@ class FileSearchBackend implements ISearchBackend {
private function transformQuery(BasicSearch $query) {
// TODO offset, limit
$orders = array_map([$this, 'mapSearchOrder'], $query->orderBy);
- return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders);
+ return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user);
}
/**
@@ -186,7 +188,7 @@ class FileSearchBackend implements ISearchBackend {
* @return ISearchOrder
*/
private function mapSearchOrder(Order $order) {
- return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToCollumn($order->property));
+ return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property));
}
/**
@@ -210,13 +212,13 @@ class FileSearchBackend implements ISearchBackend {
if (count($operator->arguments) !== 2) {
throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
}
- if (gettype($operator->arguments[0]) !== 'string') {
+ if (!is_string($operator->arguments[0])) {
throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
}
if (!($operator->arguments[1] instanceof Literal)) {
throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
}
- return new SearchComparison($trimmedType, $this->mapPropertyNameToCollumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
+ return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
case Operator::OPERATION_IS_COLLECTION:
return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
default:
@@ -228,7 +230,7 @@ class FileSearchBackend implements ISearchBackend {
* @param string $propertyName
* @return string
*/
- private function mapPropertyNameToCollumn($propertyName) {
+ private function mapPropertyNameToColumn($propertyName) {
switch ($propertyName) {
case '{DAV:}displayname':
return 'name';
@@ -238,6 +240,10 @@ class FileSearchBackend implements ISearchBackend {
return 'mtime';
case FilesPlugin::SIZE_PROPERTYNAME:
return 'size';
+ case TagsPlugin::FAVORITE_PROPERTYNAME:
+ return 'favorite';
+ case TagsPlugin::TAGS_PROPERTYNAME:
+ return 'tagname';
default:
throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName);
}
diff --git a/apps/dav/tests/unit/Files/FileSearchBackendTest.php b/apps/dav/tests/unit/Files/FileSearchBackendTest.php
index 24b9a9c51e6..539344b22d5 100644
--- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php
+++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php
@@ -122,7 +122,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -150,7 +151,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -178,7 +180,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -206,7 +209,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -234,7 +238,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')