Skip to content

Commit

Permalink
Merge pull request #4222 from nextcloud/dav-search-fileid
Browse files Browse the repository at this point in the history
Allow searching file by fileid
  • Loading branch information
rullzer authored Apr 10, 2017
2 parents afea05d + bb7e236 commit e9c6fe2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions apps/dav/lib/Files/FileSearchBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function getPropertyDefinitionsForScope($href, $path) {
new SearchPropertyDefinition('{DAV:}getlastmodified', 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),
new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),

// select only properties
new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false),
Expand All @@ -127,7 +128,6 @@ public function getPropertyDefinitionsForScope($href, $path) {
new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false),
new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false),
new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN),
new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
];
}
Expand Down Expand Up @@ -222,7 +222,7 @@ private function transformSearchOperation(Operator $operator) {
case Operator::OPERATION_IS_COLLECTION:
return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
default:
throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType. ' (' . $operator->type . ')');
throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')');
}
}

Expand All @@ -244,6 +244,8 @@ private function mapPropertyNameToColumn($propertyName) {
return 'favorite';
case TagsPlugin::TAGS_PROPERTYNAME:
return 'tagname';
case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
return 'fileid';
default:
throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName);
}
Expand All @@ -266,7 +268,7 @@ private function castValue($propertyName, $value) {
return 0 + $value;
}
$date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
default:
return $value;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ private function validateComparison(ISearchComparison $operator) {
'name' => 'string',
'size' => 'integer',
'tagname' => 'string',
'favorite' => 'boolean'
'favorite' => 'boolean',
'fileid' => 'integer'
];
$comparisons = [
'mimetype' => ['eq', 'like'],
Expand All @@ -161,6 +162,7 @@ private function validateComparison(ISearchComparison $operator) {
'size' => ['eq', 'gt', 'lt', 'gte', 'lte'],
'tagname' => ['eq', 'like'],
'favorite' => ['eq'],
'fileid' => ['eq']
];

if (!isset($types[$operator->getField()])) {
Expand Down

0 comments on commit e9c6fe2

Please sign in to comment.