Taking a hint from Perl array access, we'll allow negative
offsets for the 'o' parameter and to reverse the sort order.
my $q = PublicInbox::SearchQuery->new($ctx->{qp});
my $x = $q->{x};
my $query = $q->{'q'};
my $q = PublicInbox::SearchQuery->new($ctx->{qp});
my $x = $q->{x};
my $query = $q->{'q'};
+ my $o = $q->{o};
+ my $asc;
+ if ($o < 0) {
+ $asc = 1;
+ $o = -($o + 1); # so [-1] is the last element, like Perl lists
+ }
my $code = 200;
# double the limit for expanded views:
my $opts = {
limit => $q->{l},
my $code = 200;
# double the limit for expanded views:
my $opts = {
limit => $q->{l},
mset => 1,
relevance => $q->{r},
mset => 1,
relevance => $q->{r},
};
my ($mset, $total, $err, $cb);
retry:
};
my ($mset, $total, $err, $cb);
retry:
sub search_nav_bot {
my ($mset, $q) = @_;
my $total = $mset->get_matches_estimated;
sub search_nav_bot {
my ($mset, $q) = @_;
my $total = $mset->get_matches_estimated;
- my $end = $o + $mset->size;
- my $beg = $o + 1;
my $rv = '</pre><hr><pre id=t>';
my $rv = '</pre><hr><pre id=t>';
+ my $o = $q->{o};
+ my $off = $o < 0 ? -($o + 1) : $o;
+ my $end = $off + $mset->size;
+ my $beg = $off + 1;
+
if ($beg <= $end) {
$rv .= "Results $beg-$end of $total";
$rv .= ' (estimated)' if $end != $total;
} else {
$rv .= "No more results, only $total";
}
if ($beg <= $end) {
$rv .= "Results $beg-$end of $total";
$rv .= ' (estimated)' if $end != $total;
} else {
$rv .= "No more results, only $total";
}
+ my ($next, $join, $prev);
- if ($n < $total) {
- my $qs = $q->qs_html(o => $n, l => $l);
- $rv .= qq{ <a\nhref="?$qs"\nrel=next>next</a>}
- }
- if ($o > 0) {
- $rv .= $n < $total ? '/' : ' ';
- my $p = $o - $l;
- my $qs = $q->qs_html(o => ($p > 0 ? $p : 0));
- $rv .= qq{<a\nhref="?$qs"\nrel=prev>prev</a>};
+ if ($o >= 0) { # sort descending
+ my $n = $o + $l;
+ if ($n < $total) {
+ $next = $q->qs_html(o => $n, l => $l);
+ }
+ if ($o > 0) {
+ $join = $n < $total ? '/' : ' ';
+ my $p = $o - $l;
+ $prev = $q->qs_html(o => ($p > 0 ? $p : 0));
+ }
+ } else { # o < 0, sort ascending
+ my $n = $o - $l;
+
+ if (-$n < $total) {
+ $next = $q->qs_html(o => $n, l => $l);
+ }
+ if ($o < -1) {
+ $join = -$n < $total ? '/' : ' ';
+ my $p = $o + $l;
+ $prev = $q->qs_html(o => ($p < 0 ? $p : 0));
+ }
+
+ $rv .= qq{ <a\nhref="?$next"\nrel=next>next</a>} if $next;
+ $rv .= $join if $join;
+ $rv .= qq{<a\nhref="?$prev"\nrel=prev>prev</a>} if $prev;
bless {
q => $qp->{'q'},
x => $qp->{x} || '',
bless {
q => $qp->{'q'},
x => $qp->{x} || '',
- o => (($qp->{o} || '0') =~ /([0-9]+)/),
+ o => (($qp->{o} || '0') =~ /(-?[0-9]+)/),
l => $l,
r => (defined $r && $r ne '0'),
}, $class;
l => $l,
r => (defined $r && $r ne '0'),
}, $class;