[Maypole] Paged search results: first steps
Jesse Sheidlower
jester@panix.com
Tue, 6 Jul 2004 02:07:07 -0400
I apologize for the extremely nonspecific nature of this post,
but it's late at night and just want to get some thoughts down.
One of the problems I've had with Maypole up to now is the
lack of paged search results: When you run a search while
using a pager, the pager template takes no notice of the fact
that you're doing a search, so the links that are generated are
to the full result set, not to the searched results. We've
discussed this before on the list.
Thanks to some helpful off-list suggestions from another hacker,
I've cobbled together a system to get this to work, which I will
now describe, if not patch.
First, the search method in CDBI.pm. I generate a list of the
search params (as opposed to the entire parameter list, which
can have assorted other stuff depending on where you're coming
from), and pass this to the template:
my %search_params = map {$_ => $params{$_} }
grep { $params{$_} and $fields{$_} }
keys %params;
$r->{template_args}{search_params} = \%search_params;
(I note in passing that the search_where line in this method
has errors, in the generation of the order_by clause: the
correct syntax should be:
$r->objects([ $self->search_where(\%values,
($order ? { order_by => $order } : {}))
]);
I've submitted this to the RT queue).
Then, I created a separate search_pager template, which I
call from the list template like:
[% IF search %]
[% INCLUDE search_pager %]
[% ELSE %]
[% INCLUDE pager %]
[% END %]
The search_pager template, instead of using the "link" macro,
generates the URL's in this general way:
[% USE url("$base/$table/search", search_params) %]
and then for the link itself:
[% "[" _ '<a href="' _ url(page="${pager.next_page}") _'">' _ num _ "</a>" _ "]" %]
This isn't fully working; the base URL tends to have lots of
extra //'s, and the link generation is ugly and should be
macroified and is screwed up much of the time. And it should
account for order parameters, and perhaps others, but I
haven't gotten there yet. Still, it's probably the general
idea, so if someone is still reading and has the time to make
it work right, please let me know!
Jesse Sheidlower