[Zope] search engine question

p.t. p.training@tin.it
Thu, 04 Apr 2002 12:41:17 +0200


Hi,
I'm a newbie to Zope and this list, so I don't know if this is the correct 
way to give my contribution: if not so, please tell me what I'm expected to do.

I had a very similar problem, and I did a couple of experiments: you can 
find some code attached at the end, doing just what required using links 
for scrolling the list.
The only thing missing is the explicit request of batch size, which can be 
implemeted quite easily introducing a dedicated form-field.
To see how it works, you need to generate a REQUEST.dataTable and a method 
called rowShow which renders the table's single row.

I have also a more complex version using form and buttons, which is the one 
I prefer, because it let me to avoid URL arguments and gives me the 
possibility to handle navigation, batch infos and the list as separate 
pieces to use everywhere on the redenred page.
If you find a better way to handle the problem, let me know.
HTH,
         p.t.

At 08:54 PM 4/3/2002 -0800, Alexander Batzios wrote:
>Hi all. I am implemmenting a search engine with Zope. I have it running 
>and all, but there are three features I'm trying to implement:
>
>1. Allow the user to select the number of results per page.
>I cannot seem to be able to put a variable in the field specifying the 
>number of results per page.
>Also, how can I define that all results should be displayed in the same 
>page (in case the user selects so).
>
>2. Number the results
>How can I put a number next to each result? For e.g. in results 10-20, 
>have numbers 10,11,12 next to every result
>
>3. Show the total number of results
>Is there a way to calculate the total number of results?
>
>
>Well, any help will be greatly appreciated. I am still getting used to 
>Zope programming and DTML. The search engine works by querying a mySQL 
>database, in case it makes any difference.
>
>Thanks,
>Alex
>

+++++++++++++++ DTML Method: batcher
<dtml-comment>To keep the correct URL,
               call this method from a DTML Document using:
<dtml-var batcher>
</dtml-comment>

<dtml-comment>A table called dataTable is supposed to exist
</dtml-comment>
<dtml-unless dataTable>
   <dtml-call "REQUEST.set('dataTable', [])">
</dtml-unless>

<dtml-unless start>
   <dtml-call "REQUEST.set('start', 1)">
</dtml-unless>

<dtml-comment>This is the default batch size
</dtml-comment>
<dtml-unless batchSize>
   <dtml-call "REQUEST.set('batchSize', 10)">
</dtml-unless>

<dtml-let tableLength="_.len( dataTable )">
   <dtml-call "REQUEST.set('beginLast', 1 + tableLength - ( tableLength % 
batchSize ))">
</dtml-let>

<dtml-in dataTable size=batchSize start=start previous>
   <a href="<dtml-var absolute_url><dtml-var sequence-query>start=1">
<B>||&lt;&lt;</B>
   </a>
&nbsp;
   <a href="<dtml-var absolute_url><dtml-var sequence-query>start=<dtml-var 
previous-sequence-start-number>">
<B>&lt;&lt;</B>
   </a>
<dtml-else>
<B>||&lt;&lt;</B>
&nbsp;
<B>&lt;&lt;</B>
</dtml-in>

&nbsp;

<dtml-in dataTable size=batchSize start=start next>
   <a href="<dtml-var absolute_url><dtml-var sequence-query>start=<dtml-var 
next-sequence-start-number>">
<B>&gt;&gt;</B>
</a>
&nbsp;
   <a href="<dtml-var absolute_url><dtml-var sequence-query>start=<dtml-var 
beginLast>">
<B>&gt;&gt;||</B>
</a>
<dtml-else>
<B>&gt;&gt;</B>
&nbsp;
<B>&gt;&gt;||</B>
</dtml-in>

<BR>
Rows from
<dtml-in dataTable size=batchSize start=start previous>
<dtml-var "_['previous-sequence-end-number'] + 1">
<dtml-else>
<dtml-var start>
</dtml-in>

to
<dtml-in dataTable size=batchSize start=start next>
<dtml-var "_['next-sequence-start-number'] - 1">
<dtml-else>
<dtml-var "_.len( dataTable )">
</dtml-in>

of <dtml-var "_.len( dataTable )">

<p>
<dtml-in dataTable size=batchSize start=start>
   <dtml-let rowData="_['sequence-item']">
     <dtml-var rowShow>
   </dtml-let>
</dtml-in>
</p>