TopicIndex and my first Zope diffI played around with TopicIndex these couple of days, and in the process submitted my first Zope diff file. ain;t that exciting, or what? ;) But first off, what the heck is TopicIndex? There's little documentation available. There's the wiki and a README.txt in the directory. From the readme, it looked to me that TopicIndex is a canned query to the catalog. Say we have an object that have two fields indexed (e.g section and bodytext). Normally, in a News page, we'd want to have a link to sections. The link will then points to a page with a list of news titles. This can be done like so:
#Script python
#no binding whatsoever
#called by zpt/dtml, iterate and call object.metadata
###parameter section
return context.Catalog(query={'section':section})
With TopicIndex, we can actually make this a canned query. I'm not sure whether the results are cached or what, but the README.txt says it should be faster. Here's how to do it:
we're done. now we need to call it. we'll do that from Script (Python)
#will be called from zpt/dtml, iterate and display object.metadata
#section to call
return context.Catalog(query={'topicSection':'linuxCanned'})
That's it. Minimal test were done with about 2000+ objects in catalogs, and the difference i see is about .1s Not sure whether the time improves with more objects in catalog. Probably will. And how is this related to my first Zope diff? Well typo, mostly. The manage* forms calls it filterId, but TopicIndex.py calls it filter_id. Not much of diff, but what the heck, right? ;) Please, if you have suggestions or better ways to use TopicIndex, please do say so. Have a great weekend! |
This site conforms to the following standards:
:) i did the changes in all dtml files first, but thought better changing it to the original, ie using fieldId.
anyways, feels good.