<div dir="ltr">Hi Andy,<div><br></div><div>Folders, items, and files are all separate entities.  In terms of their tree structure, Girder models look like this:</div><div><br></div><div>* a folder's parent is either a folder, user, or collection</div><div>* an item's parent is a folder</div><div>* a file's parent is an item</div><div><br></div><div>A model can only have one parent, but multiple children.  So, folders can contain both other folders and items, but not files.  In terms of an abstract file system, there is no equivalent to an "item", it is an additional type that lies between a file and a folder.</div><div><br></div><div>Files don't have metadata associated with them, so you are probably looking to create an endpoint that searches folders and items.  It's possible you might be able to construct a single query to do this using a mongo aggregation pipeline, but I'm not certain how.  The simplest way would be to do two queries and join them together somehow.  The only endpoint that I know of that returns multiple model types is <a href="https://github.com/girder/girder/blob/master/girder/api/v1/resource.py#L68">/resource/search</a>, though I don't know I would recommend doing it that way.</div><div><br></div><div>If I were doing this, I would probably just create two different endpoints for each type.  It adds a bit of complexity to the client (two rest requests rather than one), but it is a more idiomatic restful interface.</div><div><br></div><div>Jon</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 10, 2017 at 9:25 AM, Andrés Fortier <span dir="ltr"><<a href="mailto:andres@ekumenlabs.com" target="_blank">andres@ekumenlabs.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div>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:</div><div><br></div><div><div><font face="monospace, monospace">class ResourceExt(Resource):</font></div><div><font face="monospace, monospace">    @access.public</font></div><div><font face="monospace, monospace">    @describeRoute(...)</font></div><div><font face="monospace, monospace">    def typeSearch(self, params):</font></div><div><font face="monospace, monospace">        self.requireParams(('type'), params)</font></div><div><font face="monospace, monospace">        limit, offset, sort = self.getPagingParameters(<wbr>params, 'name')</font></div><div><font face="monospace, monospace">        asset_type = params['type']</font></div><div><font face="monospace, monospace">        query = {"meta.type": asset_type}</font></div><div><font face="monospace, monospace">        fields = ['_id', 'name', 'description', 'folderId', 'public', 'access']</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">        model = ModelImporter().model('item')</font></div><div><font face="monospace, monospace">        cursor = model.find(query, fields=fields)<br></font></div><div><font face="monospace, monospace">        return list(model.<wbr>filterResultsByPermission(</font></div><div><font face="monospace, monospace">            cursor, user=self.getCurrentUser(), level=AccessType.READ,</font></div><div><font face="monospace, monospace">            limit=limit, offset=offset, removeKeys=('public', 'access')))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">def load(info):</font></div><div><font face="monospace, monospace">    ModelImporter.model('item').<wbr>ensureIndex(['meta.type', {'sparse': True}])</font></div><div><font face="monospace, monospace">    ext = ResourceExt()</font></div><div><font face="monospace, monospace">    info['apiRoot'].resource.<wbr>route('GET', ('type_search',), ext.typeSearch)</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">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:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">1. What is the relationship between items, files and folders? What are the concrete use cases for items? [1]</font></div><div><font face="arial, helvetica, sans-serif">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.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">[1] I did check the class comments and I'm a bit confused about those too. E.g. in Item it says "</font><span style="font-family:arial,helvetica,sans-serif">Items are leaves in the data hierarchy. They can contain 0 or more </span><span style="font-family:arial,helvetica,sans-serif">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?</span></div><div><span style="font-family:arial,helvetica,sans-serif"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif">Thanks in advance!</span></div><div><span style="font-family:arial,helvetica,sans-serif">Andy</span></div></div>
<br>______________________________<wbr>_________________<br>
Girder-users mailing list<br>
<a href="mailto:Girder-users@public.kitware.com">Girder-users@public.kitware.<wbr>com</a><br>
<a href="http://public.kitware.com/mailman/listinfo/girder-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/girder-users</a><br>
<br></blockquote></div><br></div>