[Zope] Returning database results similar to google search

Geir Bækholt lists at elvix.com
Fri Dec 5 16:53:45 EST 2003


On  05 Dec 2003 13:08:01 -0800 GMT 
Dylan Reinhardt asked the Zope mailinglist about the following:
  
> On Fri, 2003-12-05 at 12:12, Lyz at PrincessLeia.com wrote:
>> I'm fairly new to Zope, 

> Welcome.

>> I have a database that's full of information I'd like to return. I
>> created a Z SQL method to select * from table, and using <dtml-in ...> I
>> can return all the results I need, but there are too many.
>> 
>> I'd like to only show 5 at a time, then have a links at the bottom so
>> you can jump to database results 1-5, 6-10, 11-15, etc (much like at the
>> bottom of a google results page). 

> Here's an untested, top-of-head Python Script that assumes you pass in a
> variable called offset that defaults to 0.

>
> records = context.your_zsql_method(args)
> batch_size = 5
> 
> last_record = min([offset+batch_size,len(records)])
> 
> for record_num in range(offset, last_record):
>     print records[record_num]['some_info']
> 
> for page in range(0,len(results),batch_size):
>     print '<a href=your_url?offset=%s>%s</a>' % (page,page/batch_size)
> return printed

> It's incomplete and ugly, but should get you well on your way.

It also fetches the entire table of data from the external database
one every call, so unless you do caching, it is quite inefficient.

Either make sure these database results are cached, or check the
syntax for returning segments of results from your RMDBS and
apply Dylan's offset-logic to the ZSQL-method, instead of to the entire
resultset.

:)


-- 
__________________________________________________________________

 Geir Bækholt    ·   Interaction Architect   ·    Plone Solutions

 Development · Training · Support · http://www.plonesolutions.com
__________________________________________________________________






More information about the Zope mailing list