[Zope-CMF] searching 'subportals'

seb bacon seb@jamkit.com
Thu, 5 Jul 2001 16:08:14 +0100


> > In terms of the "portals within portals" issue, the one thing I haven't done
> > is the ability to restrict searches to sub-portals only, rather than the
> > whole site (this would also apply to the news_box). There was a recent
> > thread on this, but I haven't tried any of the suggestions yet. So if anyone
> > has tried them and found one that works nicely, I'd be glad to hear!
> Implementation detail: Because the subportals are represented by members 
> in my implementation it's easy for me to restrict searches to subportals only.
> 
> I'll give a hint (link and access) on the mailing list when I have 
> something to show.

I implemented this today by dropping in a new CatalogTool subclass. 

I've got 'Sites' inside each portal, which are portal-like objects.
Each defines a getSite method, something along the lines of
portal_url.getPortal(). 

I added a 'Site' index to the Catalog (in the enumeratedIndexes
method). 

Every time an object is indexed, the catalog_object method wraps the
object with extra information.  I added the line 

  vars['Site'] = object.getSite().getId()

to this method, so every object is now always indexed with a Site
name.

Then in the searchResults method, I added an extra criterion:

        if hasattr(self, 'getSite') and not _checkPermission(
            ManagePortal, self):
            kw['Site'] = self.getSite().getId()

Tada!

If anyone wants the whole Tool, give me a shout.  It's dead simple. 

seb