[Girder-users] Understanding Items, Files and Folders
Andrés Fortier
andres at ekumenlabs.com
Mon Jul 10 09:25:25 EDT 2017
Hi all,
I'm working on a plugin to search on Files and Folders by a metadata field
(the "type" field). The important parts of the code I have so far are:
class ResourceExt(Resource):
@access.public
@describeRoute(...)
def typeSearch(self, params):
self.requireParams(('type'), params)
limit, offset, sort = self.getPagingParameters(params, 'name')
asset_type = params['type']
query = {"meta.type": asset_type}
fields = ['_id', 'name', 'description', 'folderId', 'public',
'access']
model = ModelImporter().model('item')
cursor = model.find(query, fields=fields)
return list(model.filterResultsByPermission(
cursor, user=self.getCurrentUser(), level=AccessType.READ,
limit=limit, offset=offset, removeKeys=('public', 'access')))
def load(info):
ModelImporter.model('item').ensureIndex(['meta.type', {'sparse': True}])
ext = ResourceExt()
info['apiRoot'].resource.route('GET', ('type_search',), ext.typeSearch)
now this seems to be working ok with files, but fails to return folders, so
I think I have a wrong idea of what an item model is. I originally thought
that an item was an abstraction of both files and folders, and that
querying the item model was the way to query for both of them. I then
checked the items mongo collection and it seems there is an item record for
each file record, but none for the folder entries. So this brings up a
couple of questions:
1. What is the relationship between items, files and folders? What are the
concrete use cases for items? [1]
2. Is there a way to perform metadata-based queries on both files and
folders? I know I can do two queries (one on files and one on folders) but
then I would have to manually merge them and handle all the limit/offset
math, which seems unnecessarily complicated.
[1] I did check the class comments and I'm a bit confused about those too.
E.g. in Item it says "Items are leaves in the data hierarchy. They can
contain 0 or more files within them ...", which is confusing as I would
expect leaves to be files instead of containing them. Also if items can
contain files, doesn't that mean they are (or act as) folders?
Thanks in advance!
Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/girder-users/attachments/20170710/99b52f92/attachment.html>
More information about the Girder-users
mailing list