lib/PublicInbox/SearchView.pm | 22 ++++++++++++++++++---- diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 960049f8935cf01e011ef3983a5049598f8dc073..96b691df0e8f9149a99dab0a1a38530f6a7ecb70 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -12,13 +12,18 @@ sub sres_top_html { my ($ctx, $q) = @_; my $cgi = $ctx->{cgi}; + my $code = 200; # $q ||= $cgi->param('q'); my $o = int($cgi->param('o') || 0); my $r = $cgi->param('r'); $r = (defined $r && $r ne '0'); my $opts = { limit => $LIM, offset => $o, mset => 1, relevance => $r }; - my $mset = $ctx->{srch}->query($q, $opts); - my $total = $mset->get_matches_estimated; + my ($mset, $total); + eval { + $mset = $ctx->{srch}->query($q, $opts); + $total = $mset->get_matches_estimated; + }; + my $err = $@; my $query = PublicInbox::Hval->new_oneline($q); my $qh = $query->as_html; my $res = "$qh - search results" . @@ -32,7 +37,16 @@ PublicInbox::View::PRE_WRAP; my $foot = $ctx->{footer} || ''; $foot = qq{Back to index.}; - if ($total == 0) { + if ($err) { + my $u = 'http://xapian.org/docs/queryparser.html'; + $code = 400; + $err =~ s/^\s*Exception:\s*//; # bad word to show users :P + $err = PublicInbox::Hval->new_oneline($err)->as_html; + $res .= "\n\nBad query: $err\n"; + $res .= qq{See $u for Xapian query syntax}; + $res .= "
$foot";
+	} elsif ($total == 0) {
+		$code = 404;
 		$res .= "\n\n[No results found]

$foot";
 	} else {
 		$q = $query->as_href;
@@ -74,7 +88,7 @@ 		$res .= "\n\n" . $foot;
 	}
 
 	$res .= "
"; - [200, ['Content-Type'=>'text/html; charset=UTF-8'], [$res]]; + [$code, ['Content-Type'=>'text/html; charset=UTF-8'], [$res]]; } sub dump_mset {