[Zope] Querying ZCatalog with indexes "in OR"

Casey Duncan cduncan@kaivo.com
Mon, 09 Apr 2001 08:58:13 -0600


Ruberl Michele wrote:
> 
> Hi everybody,
> I have a ZCatalog with a lot of indexes on boolean fields.
> If I query it from DTML, it returns correctly the results of a query like
> the SQL "SELECT xxxx WHERE (A=0 AND B=0 AND C=1)"
> I'd like to query it from DTML, obtaining the results as from the SQL query
> "SELECT xxxx WHERE (A=0 OR B=0 OR C=1)"
> How can I get that? Or where can I find infos about that?
> Mik
> 

This is a limitation of ZCatalog right now. A way to "simulate" ORs on
different indexes right now is to concatenate the search results ala:

Catalog(A=0) + Catalog(B=0) + Catalog(C=1)

However you may get duplicates in the results. A better workaround for
this is to create an index that contains the calculated value and query
on it. For instance, create a python script either in your ZClass or
above the indexed objects called "A0orB0orC1" tha does this:

return context.A=0 or context.B=0 or context.C=1

Then create a separate index on A0orB0orC1.
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>