my @uid_range = @$req{qw(u U)};
$opt->{uid_range} = \@uid_range if grep(defined, @uid_range) == 2;
$opt->{threadid} = $req->{T} if defined $req->{T};
- my $mset = $req->{srch}->mset($qry_str, $opt);
- my $size = $mset->size;
- while ($size == 0 && @rest) {
- $mset = $req->{srch}->mset(shift @rest, $opt);
- $size = $mset->size;
- }
+ my ($mset, $size);
+ do {
+ eval {
+ $mset = $req->{srch}->mset($qry_str, $opt);
+ $size = $mset->size;
+ };
+ # swallow exceptions for all but the last query
+ die if $@ && !@rest;
+ } while (!$size && (defined($qry_str = shift @rest)));
say { $req->{0} } 'mset.size=', $size,
' .get_matches_estimated=', $mset->get_matches_estimated;
for my $it ($mset->items) {
static bool cmd_mset(struct req *req)
{
if (optind >= req->argc) ABORT("usage: mset [OPTIONS] WANT QRY_STR");
- const char *qry_str = req->argv[optind];
CLEANUP_FBUF struct fbuf wbuf = {};
- Xapian::MSet mset = req->code_search ? commit_mset(req, qry_str) :
+ unsigned long long size = 0;
+ Xapian::MSet mset;
+ do {
+ try {
+ const char *qry_str = req->argv[optind++];
+ mset = req->code_search ? commit_mset(req, qry_str) :
mail_mset(req, qry_str);
- unsigned long long size = mset.size();
- while (size == 0 && ++optind < req->argc) {
- qry_str = req->argv[optind];
- mset = req->code_search ? commit_mset(req, qry_str) :
- mail_mset(req, qry_str);
- size = mset.size();
- }
+ size = mset.size();
+ } catch (const Xapian::Error & e) {
+ // swallow exceptions for all but the last query
+ if (optind >= req->argc)
+ throw;
+ }
+ } while (size == 0 && optind < req->argc);
+
fbuf_init(&wbuf);
fprintf(wbuf.fp, "mset.size=%llu .get_matches_estimated=%llu\n",
size, (unsigned long long)mset.get_matches_estimated());
# ensure we can try multiple queries and return the first one
# with >0 matches
- for my $try ([[], []], [['thisbetternotmatchanything'], ['z:0..']]) {
+ for my $try ([[], []], [['thisbetternotmatchanything'], ['z:0..']],
+ [['bogus...range ignored'], []],
+ [['z:0.. dfn:Search.pm'], ['bogus...range never tried']]) {
pipe $r, $w;
+ diag explain($try);
$xhc->mkreq([$w], qw(mset), @ibx_shard_args, @{$try->[0]},
'dfn:lib/PublicInbox/Search.pm',
@{$try->[1]});
like $rank, qr/\A\d+\z/, 'rank is a digit';
is scalar(@rest), 0, 'no extra rows returned';
}
+
+ pipe $r, $w;
+ pipe $err_r, $err_w;
+ $xhc->mkreq([$w, $err_w], qw(mset), @ibx_shard_args, 'bogus...range');
+ close $w;
+ close $err_w;
+ chomp(@res = readline($r));
+ is_deeply \@res, [], 'no output on bogus query';
+ chomp(@res = readline($err_r));
+ ok scalar(@res) && $res[0], 'got error on bogus query';
+
my $nr;
for my $i (7, 8, 39, 40) {
pipe($err_r, $err_w);