Searching and only one result.
Hi everyone, I have Made a ZClass where people can add news item´s to the site. Now I added a property to the catalog when they add the news item that gets the first letter of the person who wrote the article. Now I have a search page where people can search for articles on the name of the one who wrote the article. But now the results show the same name twice if one person has written multiple articles. How can I make sure the results will only show the name of this peron once? for instance: Albert wrote 2 articles and Annie 3 a person on the site searches for the A. Now it will give Annie Annie Annie Albert Albert But the thing I want to do is that it will do this: Annie (3) click here to see all annies ........ Albert (2) click......... Can any of you help me with this? Sure hope so!! James
If you are using Oracle, you can ask it to select <name>, count(*) from <articles> where <name> like <sqlvar letter>||'%' group by <name> where <name> is your name column, containing Annie, and <articles> is the table that contains it, and <sqlvar letter> is the right DTML way of getting the letter your user provided into the query. Gasper may or may not do the same. At 15:46 10/07/01 +0200, James van der Veen wrote:
Hi everyone,
<snip>
for instance: Albert wrote 2 articles and Annie 3 a person on the site searches for the A. Now it will give Annie Annie Annie Albert Albert
But the thing I want to do is that it will do this: Annie (3) click here to see all annies ........ Albert (2) click.........
Can any of you help me with this?
Sure hope so!!
James
_______________________________________________ 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 )
A silly but working solution is this: [i do it in python script to save typing. You can do this in cluttered DTML or ZPT if you want, later] """ Will return a dictionary like this: {'Annie':3,'Albert':2} """ res={} for name in catalogsearcresult('A'): if res.has_key(name): res[name] = res[name]+1 else: res[name]=1 return res """ This can be looped over like this: for key, value in res.items(): print "<li>%s has %s articles</li>" % (key, value) """ I.e. you have to prepare and analys the search results a bit first. There are two loops here, but the second one is very simple and fast. Cheers, Peter ----- Original Message ----- From: "James van der Veen" <james@codenamefuture.nl> To: <zope@zope.org> Sent: Tuesday, July 10, 2001 3:46 PM Subject: [Zope] Searching and only one result. Hi everyone, I have Made a ZClass where people can add news item´s to the site. Now I added a property to the catalog when they add the news item that gets the first letter of the person who wrote the article. Now I have a search page where people can search for articles on the name of the one who wrote the article. But now the results show the same name twice if one person has written multiple articles. How can I make sure the results will only show the name of this peron once? for instance: Albert wrote 2 articles and Annie 3 a person on the site searches for the A. Now it will give Annie Annie Annie Albert Albert But the thing I want to do is that it will do this: Annie (3) click here to see all annies ........ Albert (2) click......... Can any of you help me with this? Sure hope so!! James _______________________________________________ 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 (3)
-
J. Cone -
James van der Veen -
Peter Bengtsson