Helm_registry.get_int "search_engine.results_per_page"
in
let results_no = List.length result in
+ let buffer = Buffer.create (200 * results_no) in
let result = paginate ~size:results_per_page ~page result in
if results_no > 0 then
let mode = "typeonly" in
- let results =
- let idx = ref ((page - 1) * results_per_page + List.length result + 1) in
- List.fold_right
- (fun uri i ->
- decr idx ;
- sprintf
- "<tr>
- <td valign=\"top\">%d.</td>
- <td><span class=\"uri\">%s</span></td>
- </tr>
- <tr>
- <td />
- <td><ht:OBJECT uri=\"%s\" mode=\"%s\"/></td>
- </tr>%s"
- !idx uri uri mode i)
- result ""
+ let output_results () =
+ let idx = ref ((page - 1) * results_per_page + 1) in
+ List.iter
+ (fun uri ->
+ incr idx;
+ Printf.bprintf buffer
+ "<tr>
+ <td valign=\"top\">%d.</td>
+ <td><span class=\"uri\">%s</span></td>
+ </tr>
+ <tr>
+ <td />
+ <td><ht:OBJECT uri=\"%s\" mode=\"%s\"/></td>
+ </tr>"
+ !idx uri uri mode) result ;
in
let summary =
sprintf "<b>%d</b> result%s found"
results_no (if results_no > 1 then "s" else "")
in
- let results =
- sprintf
- "<table xmlns:ht=\"http://www.cs.unibo.it/helm/namespaces/helm-theory\">
- %s
- </table>"
- results
- in
- (summary, results)
+ begin
+ Buffer.add_string buffer
+ "<table xmlns:ht=\"http://www.cs.unibo.it/helm/namespaces/helm-theory\">";
+ output_results ();
+ Buffer.add_string buffer "</table>";
+ (summary, Buffer.contents buffer)
+ end
else
("no results found", "")