Discussion:
[Erp5-dev] Catalog hack - searching for any category
Bartek Gorny
2006-09-05 15:20:31 UTC
Permalink
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???

If not, then here it is. The implementation is somewhat crude -
actually, it probably classifies as a dirty hack. But it works, and
doesn't seem to break things. Would be good if someone checked it.

Do we have an "experimental" in svn? ;)

Bartek
--
"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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SQLCatalog_categorySearch.patch
Type: text/x-patch
Size: 1745 bytes
Desc: not available
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20060905/5dd11c67/attachment.bin>
Jérôme Perrin
2006-09-05 21:59:33 UTC
Permalink
Post by Bartek Gorny
Hello
I tweaked the catalog, so that I could search for membership in any
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
Bartek Gorny
2006-09-06 08:37:21 UTC
Permalink
Post by Jérôme Perrin
Post by Bartek Gorny
Hello
I tweaked the catalog, so that I could search for membership in any
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???
<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
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.
Post by Jérôme Perrin
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.
Post by Jérôme Perrin
ie. context.portal_catalog(category=('function/hq','skill/expert'), )
will return all documents member of function/hq OR member of skill/expert
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
Post by Jérôme Perrin
--
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"
Loading...