[Grok-dev] Re: Newbie search tutorial
Luciano Ramalho
luciano at ramalho.org
Sun Jul 8 20:02:44 EDT 2007
I've reviewed and used the search minitutorial (thanks, Sebastian!)
and I'd like to suggest a few changes:
- Since hurry.query is not a dependency of Zope or Grok, I think the
tutorial should explain how to searches without it, and then perhaps
in a last section introduce hurry.query and show its benefits.
- There are two blanks which I think newbies would like to see filled:
1) show how the search is actually invoked. In Kirbi I did it in the
view update method, setting a view attribute called results:
http://svn.zope.org/Sandbox/luciano/kirbi/src/kirbi/pac.py?rev=77634&view=markup
or
http://tinyurl.com/yox8pw
2) show how to sort the results, since people coming from Zope 2 or an
SQL-based framework will expect the catalog to do it for them.
This is the sorting code I'd like to include as an example:
class Index(grok.View):
def update(self, query=None):
if not query: self.results = []
results = list(catalog.searchResults(title=query))
self.results = sorted(results, key=attrgetter('title'))
The attrgetter call can be replaced by lambda x:x.title but PEP-290
claims the attrgetter function in module operator is faster [2], which
may be very significant in the use case.
http://www.python.org/dev/peps/pep-0290/
If you agree, I will make the needed changes.
Cheers,
Luciano
More information about the Grok-dev
mailing list