Merge pull request #3824 from nextcloud/dav-search-getlastmodified

fix searching and ordering on getlastmodified
This commit is contained in:
Robin Appelman 2017-03-14 14:42:57 +01:00 committed by GitHub
commit 8217b16cfe
2 changed files with 9 additions and 3 deletions

View File

@ -113,7 +113,7 @@ class FileSearchBackend implements ISearchBackend {
// queryable properties
new SearchPropertyDefinition('{DAV:}displayname', true, false, true),
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
new SearchPropertyDefinition('{DAV:}getlastmodifed', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
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),
@ -236,7 +236,7 @@ class FileSearchBackend implements ISearchBackend {
return 'name';
case '{DAV:}getcontenttype':
return 'mimetype';
case '{DAV:}getlastmodifed':
case '{DAV:}getlastmodified':
return 'mtime';
case FilesPlugin::SIZE_PROPERTYNAME:
return 'size';
@ -261,6 +261,12 @@ class FileSearchBackend implements ISearchBackend {
case SearchPropertyDefinition::DATATYPE_INTEGER:
case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
return 0 + $value;
case SearchPropertyDefinition::DATATYPE_DATETIME:
if (is_numeric($value)) {
return 0 + $value;
}
$date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
default:
return $value;
}

View File

@ -216,7 +216,7 @@ class FileSearchBackendTest extends TestCase {
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
]));
$query = $this->getBasicQuery(Operator::OPERATION_GREATER_THAN, '{DAV:}getlastmodifed', 10);
$query = $this->getBasicQuery(Operator::OPERATION_GREATER_THAN, '{DAV:}getlastmodified', 10);
$result = $this->search->search($query);
$this->assertCount(1, $result);