Search

Nextcloud implements rfc5323 WebDAV search to allow clients to search for files on the server. WebDAV search allows for fairly complex search queries with filtering and sorting on multiple properties.

This document describes how to use WebDAV search with a Nextcloud server and provides some example queries, full details of the api can be found at rfc5323.

Making search requests

Search requests can be made by sending a SEARCH http request to https://cloud.example.com/remote.php/dav/ with a content type of text/xml and the query as xml in the request body.

For example, to search for text files for the user ‘test’:

  1. curl -u username:password 'https://cloud.example.com/remote.php/dav/' -X SEARCH -u test:test -H "content-Type: text/xml" --data '<?xml version="1.0" encoding="UTF-8"?>
  2. <d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
  3. <d:basicsearch>
  4. <d:select>
  5. <d:prop>
  6. <oc:fileid/>
  7. <d:displayname/>
  8. <d:getcontenttype/>
  9. <d:getetag/>
  10. <oc:size/>
  11. </d:prop>
  12. </d:select>
  13. <d:from>
  14. <d:scope>
  15. <d:href>/files/test</d:href>
  16. <d:depth>infinity</d:depth>
  17. </d:scope>
  18. </d:from>
  19. <d:where>
  20. <d:like>
  21. <d:prop>
  22. <d:getcontenttype/>
  23. </d:prop>
  24. <d:literal>text/%</d:literal>
  25. </d:like>
  26. </d:where>
  27. <d:orderby/>
  28. </d:basicsearch>
  29. </d:searchrequest>'

Supported DAV properties

The following DAV properties are supported for use in either select, where and orderby, not all properties can be used for each operation.

Property nameDescriptionSelectableSearchableSortableType
{DAV:}displaynameFile nameString
{DAV:}getcontenttypeMime typeString
{DAV:}getlastmodifiedModified dateDatetime
{http://owncloud.org/ns}sizeFile size or folder sizeInteger
{http://owncloud.org/ns}favoriteFavorite statusBoolean
{http://owncloud.org/ns}fileidNextcloud file idInteger
{DAV:}resourcetypeFile or folderString
{DAV:}getcontentlengthFile size, not for foldersString
{http://owncloud.org/ns}checksumsStored checksums for the fileString
{http://owncloud.org/ns}permissionsFile permissionsString
{DAV:}getetagFile etagString
{http://owncloud.org/ns}owner-idFile ownerString
{http://owncloud.org/ns}owner-display-nameFile owner display nameString
{http://owncloud.org/ns}data-fingerprintFingerprint for recovery statusString
{http://nextcloud.org/ns}has-previewPreview statusBoolean

Search scope

All search queries are scoped to a single folder relative to the dav root. At the moment only search queries for files are supported meaning the the scope should always start with files/$username.

Inside the user’s files, any existing folder can be used as search scope.

Examples search bodies

Search for all plain text files in the folder Documents, sorted by size.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
  3. <d:basicsearch>
  4. <d:select>
  5. <d:prop>
  6. <d:displayname/>
  7. </d:prop>
  8. </d:select>
  9. <d:from>
  10. <d:scope>
  11. <d:href>/files/test/Documents</d:href>
  12. <d:depth>infinity</d:depth>
  13. </d:scope>
  14. </d:from>
  15. <d:where>
  16. <d:like>
  17. <d:prop>
  18. <d:getcontenttype/>
  19. </d:prop>
  20. <d:literal>text/%</d:literal>
  21. </d:like>
  22. </d:where>
  23. <d:orderby>
  24. <d:prop>
  25. <oc:size/>
  26. </d:prop>
  27. <d:ascending/>
  28. </d:orderby>
  29. </d:basicsearch>
  30. </d:searchrequest>

Get a file by id.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
  3. <d:basicsearch>
  4. <d:select>
  5. <d:prop>
  6. <d:displayname/>
  7. </d:prop>
  8. </d:select>
  9. <d:from>
  10. <d:scope>
  11. <d:href>/files/test</d:href>
  12. <d:depth>infinity</d:depth>
  13. </d:scope>
  14. </d:from>
  15. <d:where>
  16. <d:eq>
  17. <d:prop>
  18. <oc:fileid/>
  19. </d:prop>
  20. <d:literal>12345</d:literal>
  21. </d:eq>
  22. </d:where>
  23. <d:orderby/>
  24. </d:basicsearch>
  25. </d:searchrequest>

Get all png and jpg files over 10MB.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
  3. <d:basicsearch>
  4. <d:select>
  5. <d:prop>
  6. <d:displayname/>
  7. </d:prop>
  8. </d:select>
  9. <d:from>
  10. <d:scope>
  11. <d:href>/files/test</d:href>
  12. <d:depth>infinity</d:depth>
  13. </d:scope>
  14. </d:from>
  15. <d:where>
  16. <d:and>
  17. <d:or>
  18. <d:eq>
  19. <d:prop>
  20. <d:getcontenttype/>
  21. </d:prop>
  22. <d:literal>image/png</d:literal>
  23. </d:eq>
  24. <d:eq>
  25. <d:prop>
  26. <d:getcontenttype/>
  27. </d:prop>
  28. <d:literal>image/jpg</d:literal>
  29. </d:eq>
  30. </d:or>
  31. <d:gt>
  32. <d:prop>
  33. <oc:size/>
  34. </d:prop>
  35. <d:literal>10000000</d:literal>
  36. </d:gt>
  37. </d:and>
  38. </d:where>
  39. <d:orderby/>
  40. </d:basicsearch>
  41. </d:searchrequest>