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

Bartek Gorny bartek at redpoint.mn.pl
Wed Sep 6 10:37:21 CEST 2006


On 05/09/06, Jérôme Perrin <jerome at nexedi.com> wrote:
> 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

Oh, I see. I thought it could be something like that, but didn't know
enough about related keys automagic. BTW, couldn't this key be in
bootstrap? It is so useful.

> 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.

Well, in this case I really need AND. It is true that it should be
more generic. Actually, maybe we can assume that if a user provides
multiple values with different base categories he does so to narrow
the search, not widen, so we can safely AND them; and if there are
multiple values from the same base category, they obviously should be
ORed.

> 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.

I think it is a missing feature - as we just proved, to be really
useful the catalog should provide an option to AND multiple values. Or
a way for a related key to receive and process an argument passed as a
tuple, so that it can do it by itself - from what I see, tuple
arguments are split and items are passed separately?

Bartek

>
> --
> Jérome
>


-- 
"Software is largely a service industry operating under the persistent
but unfounded delusion that it is a manufacturing industry."
Eric S.Raymond, "The Magic Cauldron"



More information about the Erp5-dev mailing list