[Zope-dev] intersection of ZCatalog queries on the same index

Michel Pelletier michel@digicool.com
Thu, 05 Oct 2000 15:31:14 -0700


Neil K wrote:
> 
> If there a way to get ZCatalog to give me intersections of results on a
> single index? All the examples and tutorials I've seen are union (OR)
> queries.
> 
> Basically I just want ZCatalog to give me items where keywords contained
> both 'foo' and 'bar'.

You should use a Keyword Index for this.  If your KW index was named
'food' and all your objects had a 'food' sequence attribute, then:

Catalog.searchResults({'food', ['foo', 'bar']})

would find all of the objects whose food property contained both 'foo'
_and_ 'bar'.

> I have browsed through Catalog.py and it seems like it might be possible.
> Disclaimer, I'm pretty new to Zope & python.

In the general case, it's not possible without redesigning Zope's
catalog query language (which implicitly ORs all index queries
together).  For the special case of keywords, use a keyword index.

-Michel