+sub add_misc_ibx { # MiscSearch->retry_reopen callback
+ my ($misc, $ctx, $re, $qs) = @_;
+ require PublicInbox::SearchQuery;
+ my $q = $ctx->{-sq} = PublicInbox::SearchQuery->new($ctx->{qp});
+ my $o = $q->{o};
+ my ($asc, $min, $max);
+ if ($o < 0) {
+ $asc = 1;
+ $o = -($o + 1); # so [-1] is the last element, like Perl lists
+ }
+ my $r = $q->{r};
+ my $opt = {
+ offset => $o,
+ asc => $asc,
+ relevance => $r,
+ limit => $q->{l}
+ };
+ $qs .= ' type:inbox';
+ if (my $user_query = $q->{'q'}) {
+ $qs = "( $qs ) AND ( $user_query )";
+ }
+ my $mset = $misc->mset($qs, $opt); # sorts by $MODIFIED (mtime)
+ $ctx->{-list} = [];
+ my $pi_cfg = $ctx->{www}->{pi_cfg};
+ for my $mi ($mset->items) {
+ my $doc = $mi->get_document;
+ my ($eidx_key) = PublicInbox::Search::xap_terms('Q', $doc);
+ $eidx_key // next;
+ my $ibx = $pi_cfg->lookup_eidx_key($eidx_key) // next;
+ next if $ibx->{-hide}->{$ctx->hide_key};
+ grep(/$re/, @{$ibx->{url}}) or next;
+ $ctx->ibx_entry($ibx, $misc->doc2ibx_cache_ent($doc));
+ if ($r) { # for descriptions in search_nav_bot
+ my $pct = PublicInbox::Search::get_pct($mi);
+ # only when sorting by relevance, ->items is always
+ # ordered descending:
+ $max //= $pct;
+ $min = $pct;
+ }
+ }
+ if ($r) { # for descriptions in search_nav_bot
+ $q->{-min_pct} = $min;
+ $q->{-max_pct} = $max;
+ }
+ $ctx->{-mset} = $mset;
+ psgi_triple($ctx);
+}
+