Hi, I've implemented an OR search for ZCatalog following the HowTos and mailing list postings. However I am still trying to solve the problem that a search result shows up twice when it matches two subsearch criteria. I tried a Python Method "uniq" to make the results of the search unique, but get an error "Error Type: AttributeError Error Value: __hash__". dtml: <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> ... python method (parameter "items"): d = {} for item in items: d.update( { item: 1 } ) return d.keys() stack trace: ... File /opt2/cvs/Zope2/lib/python/Products/PythonScripts/PythonScript.py, line 337, in _exec (Object: uniq) (Info: ({'script': <PythonScript instance at 8c73b88>, 'context': <Folder instance at 8c95b88>, 'container': <Folder instance at 8968e08>, 'traverse_subpath': []}, (), {'items': [<mybrains instance at 8b215d0>, <mybrains instance at 8c2e778>, ..... File Script (Python), line 5, in uniq .. why can't I iterate over the "items" search results as a normal list? Is there any way to make this work? thanks for your help --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()
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 )
participants (1)
-
Oliver Frommel