[Zope] Getting counts from a ZCatalog - it must be easier than my feeble attempt!

S.Wilson s.wilson@bangor.ac.uk
Fri, 03 Aug 2001 16:08:38 +0100


Hi all,

I need to find out how many results would be returned from a search,
without necessarily getting the results set itself. Currently the only way
I can do this is to iterate through a zcatalog using <dtml-in> and add up
the number of items. <dtml-var> does not support functions such as len(),
but I'm convinced I'm missing something, and there is a considerably more
elegant solution to this one...

Here's my code:

1: <P><b>Subjects</b><br>
2: <dtml-in expr="('SubjectContext'),('AudienceContext')">
3:	<dtml-let sIndex=sequence-key>
4:		<dtml-in expr="articleIndex.uniqueValuesFor(sIndex)" >
5:			<dtml-call "REQUEST.set('nItemCount',0)">
6:			<dtml-in expr="articleIndex({sIndex:_.getitem('sequence-item')})">
7:				<dtml-call "REQUEST.set('nItemCount',nItemCount+1)">
8:			</dtml-in>
9:			<a href="/index_html?<dtml-var sIndex>=<dtml-var sequence-item>">
10:				<dtml-var sequence-item capitalize>
11:                    	</a>
12:                        (<dtml-var nItemCount>)<br>
13:                 </dtml-in>
14:        </dtml-let>
15: </dtml-in>
16: </P>

which outputs a side menu bar looking something along these lines:

Subjects:
Assessment (2)
Content (3)
Metadata (5)
For Developers (5)
For Educators (3)
For Members (2)


What I'm looking for is something like:

<dtml-var
expr="len(articleIndex({'SubjectContext':_.getitem('sequence-item')})[0])">

to replace lines 5,6,7. Unfortunately this gives me an error.

Any ideas?

Thanks,

Scott
Zope Newbie