[Grok-dev] Re: Newbie search tutorial
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:
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:
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 , which
may be very significant in the use case.
If you agree, I will make the needed changes.
More information about the Grok-dev