[Zope-CMF] Create search for folders
Tres Seaver
tseaver@palladion.com
Wed, 18 Jul 2001 07:59:57 -0400 (EDT)
On Wed, 18 Jul 2001, Yoke May Seow wrote:
> I still can't figure out how to create a search criteria that
> only allows me to search within the a folder and its
> sub-folder.
>
> Anyone can help me on this? Appreciate it a lot. Thanks.
Zope 2.4 adds a new index type, 'PathIndex', which is aimed at
making this a no-brainer. Until then, you can achieve the effect
in a couple of ways:
- Add a property to each folder at a given "level" which identifies
it uniquely among its peers; add a field index to the catalog
on that property, and search it.
- Add an ExternalMethod which generates a set of path prefixes for
an object, and catalog its results with a keyword index. This
script might look something like (untested):
from Products.CMFCore.utils import getToolByName
def getPathPrefixes( self ):
"""
Return the set of path prefixes for a given object;
the result will be a tuple of tuples, e.g.:
( ( '', )
, ( '', 'Members' )
, ( '', 'Members', 'tres' )
, ( '', 'Members', 'tres', 'index_html' )
)
"""
tool = getToolByName( self, 'portal_url' )
path = tool.getRelativeContentPath( self ) # tuple of IDs
result = []
for i in range( len( path ) ):
result.append( path[ : i+1 ] )
return tuple( result )
Tres.
--
===============================================================
Tres Seaver tseaver@digicool.com
Digital Creations "Zope Dealers" http://www.zope.org