[Erp5-dev] Catalog hack - searching for any category

Jérôme Perrin jerome at nexedi.com
Tue Sep 5 23:59:33 CEST 2006


Le Mardi 5 Septembre 2006 17:20, Bartek Gorny a écrit :
> Hello
>
> I tweaked the catalog, so that I could search for membership in any
> category, like:
> context.portal_catalog(category='function/hq')
> or
> context.portal_catalog(category=('function/hq','skill/expert'),title='John'
>)
>
> First, have I done again something that was already there???

I think you can achieve something somehow similar by adding this related key:

<params>query_table
table_0
table_1</params>
<dtml-var table_1>.uid = <dtml-var table_0>.category_uid
AND <dtml-var table_0>.uid = <dtml-var query_table>.uid

registred like this:

category | category,catalog/relative_url/z_related_category

This will not be exactly the same, because you made an explicit AND in your 
patch, whereas with multiple values, we have a OR by default.
ie. context.portal_catalog(category=('function/hq','skill/expert'), )
will return all documents member of function/hq OR member of skill/expert

if you want function/hq AND skill/expert, you can use a dict, like that:
 context.portal_catalog( 
            category={'query': ('function/hq', 'skill/expert'),
                               'operator': 'AND'})

Unfortunatly, this will not work, because it uses the same table in the 
generated SQL, and something like "(related_catalog_57.relative_url = 
'skill/expert' AND related_catalog_57.relative_url = 'function/hq')", which 
is an impossible query.
This is probably a bug (is it ?), but I have the feeling I am misunderstanding 
the use of 'AND' operator.

-- 
Jérome



More information about the Erp5-dev mailing list