[Zope] Finding unique objects in a ZCatalog returned list

Casey Duncan cduncan@kaivo.com
Thu, 21 Jun 2001 08:59:59 -0600


Mike Groves wrote:
> 
> Hello,
> 
> I'm doing quick search using several indexes in a ZCatalog as below
> 
> <dtml-in expr="Catalog(title=query) +
>                Catalog(category=query) +
>                Catalog(description=query) +
>                Catalog(product=query) +
>                Catalog(keywords=query)">
> 
> This works really well. However, if my query string is found in more than
> one index I get the same object returned more than once.
> 
> How do I sort the list of objects returned and more importantly remove
> duplicate objects?
> 
> Thanks for any help.
> 

Another approach would be to create a Py script as an instance method of
the ZClass that concatenates all of these properties values and returns
the result. Something like:

return container.title + '\n' + container.category + '\n' +
container.description + '\n' + ...

Then create an TextIndex in your ZCatalog with the same name as the
script. Use this index for your search and you won't have to worry about
duplicate results.

-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>