+ # HTML view always wants an array and never uses $prev,
+ # but the mbox stream never wants an array and always has $prev
+ die '$prev not supported with wantarray' if $prev;
+ my $nr = $dbh->selectrow_array(<<"", undef, $tid, $sid, $num);
+SELECT COUNT(num) FROM over WHERE $cond_all
+
+ # giant thread, prioritize strict (tid) matches and throw
+ # in the loose (sid) matches at the end
+ my $msgs = do_get($self, <<"", {}, $tid, $num);
+SELECT $cols FROM over WHERE tid = ? AND num > ?
+ORDER BY $sort_col ASC
+
+ # do we have room for loose matches? get the most recent ones, first:
+ my $lim = DEFAULT_LIMIT - scalar(@$msgs);
+ if ($lim > 0) {
+ my $opts = { limit => $lim };
+ my $loose = do_get($self, <<"", $opts, $tid, $sid, $num);
+SELECT $cols FROM over WHERE tid != ? AND sid = ? AND num > ?
+ORDER BY $sort_col DESC
+
+ # TODO separate strict and loose matches here once --reindex
+ # is fixed to preserve `tid' properly
+ push @$msgs, @$loose;
+ }