How to join/add ZCatalog.searchResults?
Problem: I need to combine a search in two fields (title, data) with or. (standard is and, and since now there is no chance to change this, afaik?) A solution could be, to make two separate searches and join the searchResults, something like this: <dtml-let title_search="Catalog.searchResults({'title':mysearchfield})" data_search="Catalog.searchResults({'data':mysearchfield})" complete_search="title_search + data_search"> and then iterate over the concatenated list: <dtml-in complete_search size=20 start=query_start> Well, I'd love to try this, but "title_search + data_search" doesn't work. Error Type: TypeError Error Value: __add__ nor __radd__ defined for these operands Any idea how to concatenate those two searchResults? Thanks in advance, Michael gutmann@uni-duesseldorf.de
At 11:35 15/10/99 , Michael Gutmann wrote:
Problem: I need to combine a search in two fields (title, data) with or. (standard is and, and since now there is no chance to change this, afaik?)
A solution could be, to make two separate searches and join the searchResults, something like this:
<dtml-let title_search="Catalog.searchResults({'title':mysearchfield})" data_search="Catalog.searchResults({'data':mysearchfield})" complete_search="title_search + data_search">
and then iterate over the concatenated list:
<dtml-in complete_search size=20 start=query_start>
Well, I'd love to try this, but "title_search + data_search" doesn't work.
Error Type: TypeError Error Value: __add__ nor __radd__ defined for these operands
Any idea how to concatenate those two searchResults?
Try: title_search[:] + data_search[:]. The result object from a Catalog query supports slicing, and this also works when there is only one result (because then the returned set is just a python list). ZCatalog uses an object that avoids loading the whole result list into memory if it possibly can help it. Above solution will completely destroy this effort of course. -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
<...>
Try: title_search[:] + data_search[:]. The result object from a Catalog query supports slicing, and this also works when there is only one result (because then the returned set is just a python list).
ZCatalog uses an object that avoids loading the whole result list into memory if it possibly can help it. Above solution will completely destroy this effort of course.
-- Martijn Pieters, Web Developer
Hmm, no chance, Zope complains with: Error Type: MemoryError Error Value: that seems to be raised by the controlling method you mentioned File /www/WWW/Zope/2.0.1/lib/python/DocumentTemplate/DT_Util.py, line 170, in careful_getslice File /www/WWW/Zope/2.0.1/lib/python/Products/ZCatalog/Lazy.py, line 109, in __getslice__ MemoryError: (see above) and there ist only one item in each searchResult. Are the searchResult objects that big, that there has to be such a restriction? Michael Gutmann gutmann@uni-duesseldorf.de
participants (2)
-
Martijn Pieters -
Michael Gutmann