Support timeExceeded in second frontend
diff --git a/lib/Korap/Plugin/KorapSearch.pm b/lib/Korap/Plugin/KorapSearch.pm
index 70a539b..c22b4b6 100644
--- a/lib/Korap/Plugin/KorapSearch.pm
+++ b/lib/Korap/Plugin/KorapSearch.pm
@@ -1,7 +1,7 @@
package Korap::Plugin::KorapSearch;
use Mojo::Base 'Mojolicious::Plugin';
use Scalar::Util qw/blessed/;
-use Mojo::JSON qw/decode_json/;
+use Mojo::JSON qw/decode_json true/;
use Mojo::ByteStream 'b';
# TODO: This will probably be an engine for M::P::Search
@@ -155,14 +155,6 @@
my $json = $res->json;
# Reformat benchmark counter
-# my $b_hit = $json->{benchmarkHitCounter};
-# my $b_search = $json->{benchmarkSearchResults};
-# if ($b_hit && $b_hit =~ s/\s+(m)?s$//) {
-# $b_hit = sprintf("%.2f", $b_hit) . ($1 ? $1 : '') . 's';
-# };
-# if ($b_search && $b_search =~ s/\s+(m)?s$//) {
-# $b_search = sprintf("%.2f", $b_search) . ($1 ? $1 : '') . 's';
-# };
my $benchmark = $json->{benchmark};
if ($benchmark && $benchmark =~ s/\s+(m)?s$//) {
$benchmark = sprintf("%.2f", $benchmark) . ($1 ? $1 : '') . 's';
@@ -171,6 +163,9 @@
for ($c->stash) {
$_->{'search.benchmark'} = $benchmark;
$_->{'search.itemsPerPage'} = $json->{itemsPerPage};
+ $_->{'search.timeExceeded'} = (defined $json->{timeExceeded} &&
+ $json->{timeExceeded} eq true())
+ ? 1 : 0;
$_->{'search.query'} = $json->{request}->{query};
$_->{'search.hits'} = map_matches($json->{matches});
};
diff --git a/templates/search.html.ep b/templates/search.html.ep
index abab210..077e93b 100644
--- a/templates/search.html.ep
+++ b/templates/search.html.ep
@@ -8,7 +8,13 @@
% $pages = $pages < 0 ? 0 : $pages;
<div id="pagination"><%= pagination(stash('search.startPage'), $pages, $url) =%></div>
<p class="found">Found
- <span id="total-results"><% if (stash('search.totalResults') == -1) { %>unknown<% } else { %><%= commify(stash('search.totalResults')) %><% } %> matches</span>
+% my $found = stash('search.totalResults');
+% if ($found == -1) {
+% $found = 'unknown amount of';
+% } elsif (stash('search.timeExceeded')) {
+% $found = 'more than ' . $found;
+% };
+ <span id="total-results"><%= $found %> matches</span>
<% if (stash 'search.benchmark') { %> in <%= stash 'search.benchmark' %><% } %>
</p>
</div>
@@ -16,7 +22,7 @@
%= include 'api-communication'
% };
-% unless (stash('search.totalResults') == 0) {
+% if (stash('search.totalResults') != 0 && scalar @{stash('search.hits')}) {
<div id="search">
<ol class="left-aligned">
%= search_hits begin