[Zope] ZCatalog OR search problems (solved)

Oliver Frommel oliver@aec.at
Sat, 24 Feb 2001 17:47:25 +0100 (CET)


finally I got it working and maybe it helps someone else ..
you can't necessarily eliminate duplicates from the ZCatalog search results by
sorting the mybrains because the same object in the ZODB may be denoted my two
different mybrains as far as I understand.

so my "solution" was to make the absolute URLs the keys of a dictionary and
return the values(), i.e. the mybrains:

PythonMethod "uniq" (parameter "items" contains the results of a Catalog query):
d = {}
for item in items:
    url = item.getURL()
    d.update( { url: item } )
return d.values()

you can call it like that:
<dtml-let resa="Catalog(text_obj=begriff)"
           resb="Catalog(abstract_obj=begriff)"
           resc="Catalog(title=begriff)"
           res="resa[:_.len(resa)] + resb[:_.len(resb)] + resc[:_.len(resc)]">
<dtml-in "uniq(items=res)" size=50 start=query_start>
....

you have to decide for yourself if this is what you want :)
sorry for the disturbance.
--Oliver


> 
> ok, I see the problem is using the mybrain instances as keys in the dictionary
> which doesn't work (in Python anyway). So I've switched to using a list and
> somehow it works (ie. no errors) but doesn't return a list with unique 
> values. Is it possible to test for equality of mybrains (I assume this is 
> what the "in" operator uses somewhere)??
> 
> here's the new code:
> def uniq2(items):
>    arr = []
>    for item in items:
>        if not item in arr:
>           arr.append(item)
>    return arr
> 
> 
> thanks for any help
> --Oliver
> 
> > 
> > <dtml-in "uniq(items=res)" size=50 start=query_start>
> > ...
> > 
> > python method (parameter "items"):
> > d = {}
> > for item in items:
> >     d.update( { item: 1 } )
> > return d.keys()
> > 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>