I am performing a search inside a folder. Unfortunately, it retrieves also the root folder, and I do not want that.
An example is as follows. If I have a directory structure similar to the one below:
RootFolder
... SubFolder1
... SubFolder2
I expect to get the following when I search inside RootFolder directory:
SubFolder1
SubFolder2
But instead, this is what I get:
RootFolder
SubFolder1
SubFolder2
I do not want the root to be displayed. Below is the code that I use to fetch/search the items within a folder:
def queryItemRepository(self):
"""
Perform a search
"""
query = {}
portal_catalog = getToolByName(self, 'portal_catalog')
folder_path = '/'.join( self.context.getPhysicalPath() )
query['path'] = {'query' : folder_path, 'depth' : 2 }
query['sort_on'] = "sortable_title"
query['sort_order'] = "ascending"
return portal_catalog.searchResults(query)
The
depthparameter in path searches limits the depth of the search, it does not set a minimal level. So, in your search, all paths starting atfolder_pathup to and including 2 nested levels of children are returned.Just filter out the root path; you already have the context so you can just compare URL of each item: