[Zope] Searching Multiple Fields in ZCatalog

kapil thangavelu kthangavelu@earthlink.net
Fri, 29 Mar 2002 14:04:54 -0800


On Friday 29 March 2002 07:13 pm, kedai@kedai.com.my wrote:
> >I'm sure this has been covered, but I can't find an answer.
> >
> >I need to perform a search across three different fields in my zcatalog.
> >Currently, the only way I can see to do this is with three distinct form
> >fields. I wish to have my users enter their query in only one form field,
> >and still search each of the three zcatalog indices.
> >
> >Any suggestions?
>
> zope 2.5.1b1
> in pythonscript, concat the result of the query like so
>
> o=getattr(context,'Catalog')
> r=o(index1={'query':'myquery'}) + o(index2={'query':'query2'})
> return r
>
> there maybe better ways, but thsi is how i did it

this works, but adds some extra overhead as you go through the entire 
zcatalog query process several times. you can search a catalog on multiple 
indexes by passing each index name and its query args as keyword names to the 
catalog... ie for a simple case the above translates to

o(index1=query, index2=query2)

thus the full catalog search machinery is invoked only once and internally  
(and more efficiently) the catalog will merge the results 

as per the original question, use a python script to break up the form input 
appropriately to search the individual indexes.

-kapil