Added cutoff functionality for tutorial queries
diff --git a/lib/Korap/Plugin/KorapSearch.pm b/lib/Korap/Plugin/KorapSearch.pm
index fd30c15..70a539b 100644
--- a/lib/Korap/Plugin/KorapSearch.pm
+++ b/lib/Korap/Plugin/KorapSearch.pm
@@ -74,7 +74,8 @@
1
));
- my $query = $param{query} // scalar $c->param('q');
+ my $query = $param{query} // scalar $c->param('q');
+ my $cutoff = $param{cutoff} // scalar $c->param('cutoff') // undef;
return '' unless $query;
@@ -108,6 +109,7 @@
my %query = (q => $query);
$query{ql} = scalar $c->param('ql') // 'poliqarp';
$query{count} = $count if $count;
+ $query{cutoff} = 'true' if $cutoff;
$url->query(\%query);
my $cache_url = $url->to_string;
@@ -119,7 +121,9 @@
if (defined $total_results) {
$c->stash('search.totalResults' => $total_results);
$c->app->log->debug('Get total result from cache');
- $url->query({cutoff => 'true'});
+
+ # Set cutoff unless already set
+ $url->query({cutoff => 'true'}) unless defined $cutoff;
}
else {
$c->stash('search.totalResults' => 0);
@@ -173,10 +177,10 @@
if ($json->{totalResults} && $json->{totalResults} > -1) {
$c->app->log->debug('Cache total result');
- $c->stash('search.totalResults' => $json->{totalResults});
$c->chi->set('total-' . $cache_url => $json->{totalResults}, '30min');
};
+ $c->stash('search.totalResults' => $json->{totalResults});
if ($json->{warning}) {
$c->notify(warn => $json->{warning});
};
diff --git a/lib/Korap/Plugin/KorapTagHelpers.pm b/lib/Korap/Plugin/KorapTagHelpers.pm
index 25ca691..6ce4af2 100644
--- a/lib/Korap/Plugin/KorapTagHelpers.pm
+++ b/lib/Korap/Plugin/KorapTagHelpers.pm
@@ -8,15 +8,18 @@
$mojo->helper(
korap_tut_query => sub {
- my ($c, $ql, $q) = @_;
+ my ($c, $ql, $q, %param) = @_;
my $onclick = 'top.useQuery(this)';
if ($c->param('embedded')) {
$onclick = 'setTutorialPage(this);' . $onclick;
};
$q = xml_escape $q;
b('<pre class="query tutorial" onclick="' . $onclick . '" ' .
- qq!data-query="$q" data-query-language="$ql"><code>! .
- $q . '</code></pre>');
+ qq!data-query="$q" data-query-cutoff="! .
+ ($param{cutoff} ? 1 : 0) .
+ '"' .
+ qq! data-query-language="$ql"><code>! .
+ $q . '</code></pre>');
}
);
diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep
index c5ab254..2c2030c 100644
--- a/templates/layouts/default.html.ep
+++ b/templates/layouts/default.html.ep
@@ -50,7 +50,7 @@
<div id="top">
<a href="<%= url_for 'index' %>"><h1><span>KorAP- Korpusanalyseplattform der nächsten Generation</span></h1></a>
-%= form_for $search_route => begin
+%= form_for $search_route, autocomplete => 'off' => begin
<div id="searchbar">
%= search_field 'q', id => 'q-field', autofocus => 'autofocus', placeholder => 'Find ...'
<button type="submit"><i class="fa fa-search"></i></button>
@@ -63,7 +63,7 @@
<div class="select">
%= select_field ql => [[Poliqarp => 'poliqarp'], ['Cosmas II' => 'cosmas2'], ['Annis' => 'annis'], ['CQL v1.2' => 'cql']], id => 'ql-field'
</div>
-
+%= hidden_field 'cutoff' => 0, id => 'q-cutoff-field'
<div id="button-right">
% unless (current_route 'tutorial') {
diff --git a/templates/match.html.ep b/templates/match.html.ep
index 19d459a..447ad32 100644
--- a/templates/match.html.ep
+++ b/templates/match.html.ep
@@ -13,7 +13,7 @@
% if ($match->{title}) {
<strong><%= $match->{title} %></strong>
% };
- <%= $match->{author} ? ' by ' . $match->{author} : '' %><% if ($match->{title} || $match->{author}) %>;<% } %>
+ <%= $match->{author} ? ' by ' . $match->{author} : '' %><% if ($match->{title} || $match->{author}) { %>;<% } %>
published on <%= date_format $match->{pubDate} %>
as <%= $match->{docID} %> (<%= $match->{corpusID} %>)
</p>
diff --git a/templates/partial/javascript.html.ep b/templates/partial/javascript.html.ep
index 2281441..055ddf2 100644
--- a/templates/partial/javascript.html.ep
+++ b/templates/partial/javascript.html.ep
@@ -17,6 +17,7 @@
"ne_dewac_175m_600" : ["ne_dewac_175m_600=", "Named Entity"],
"ne_hgc_175m_600" : ["ne_hgc_175m_600=", "Named Entity"]
},
+ "corenlp/ne" : ["I-LOC","I-MISC","I-ORG","I-PER"],
"corenlp/ne_dewac_175m_600" : ["I-LOC","I-MISC","I-ORG","I-PER"],
"corenlp/ne_hgc_175m_600" : ["I-LOC","I-MISC","I-ORG","I-PER"],
"cnx" : {
@@ -75,8 +76,12 @@
function useQuery (o) {
var q = o.getAttribute("data-query");
var ql = o.getAttribute("data-query-language");
+ var qc = o.getAttribute("data-query-cutoff");
+ if (qc === null)
+ qc = 0;
$("#ql-field").val(ql);
$("#q-field").val(q);
+ $("#q-cutoff-field").val(qc);
closeTutorial();
};
diff --git a/templates/search.html.ep b/templates/search.html.ep
index 47191b9..abab210 100644
--- a/templates/search.html.ep
+++ b/templates/search.html.ep
@@ -8,7 +8,7 @@
% $pages = $pages < 0 ? 0 : $pages;
<div id="pagination"><%= pagination(stash('search.startPage'), $pages, $url) =%></div>
<p class="found">Found
- <span id="total-results"><%= commify(stash('search.totalResults')) %> matches</span>
+ <span id="total-results"><% if (stash('search.totalResults') == -1) { %>unknown<% } else { %><%= commify(stash('search.totalResults')) %><% } %> matches</span>
<% if (stash 'search.benchmark') { %> in <%= stash 'search.benchmark' %><% } %>
</p>
</div>
diff --git a/templates/tutorial/index.html.ep b/templates/tutorial/index.html.ep
index cf112fb..a76de5c 100644
--- a/templates/tutorial/index.html.ep
+++ b/templates/tutorial/index.html.ep
@@ -43,10 +43,10 @@
%= korap_tut_query cosmas2 => 'der /w5 Baum'
<p><strong>Poliqarp+</strong>: Find all nominal phrases as annotated using Connexor, that contain an adverb as annotated by OpenNLP.</p>
-%= korap_tut_query poliqarp => 'contains(<cnx/c=np>,[opennlp/p=ADV])'
+%= korap_tut_query poliqarp => 'contains(<cnx/c=np>,[opennlp/p=ADV])', cutoff => 1
<p><strong>Poliqarp+</strong>: Find all sentences as annotated by the base foundry that start with a sequence of one token in present tense as annotated by Connexor and the lemma "der" annotated by the <%= korap_tut_link_to 'default foundry', '/tutorial/foundries' %>. Highlight both terms of the sequence.</p>
-%= korap_tut_query poliqarp => 'startswith(<s>, {1:[cnx/m=PRES]}{2:[base=der]})'
+%= korap_tut_query poliqarp => 'startswith(<s>, {1:[cnx/m=PRES]}{2:[base=der]})', cutoff => 1
<p><strong>Annis</strong>: Find all occurrences of the sequence of two tokens annotated as adverbs by the <%= korap_tut_link_to 'default foundry', '/tutorial/foundries' %>.</p>
%= korap_tut_query annis => 'pos="ADV" & pos="ADV" & #1 . #2'