Small changes to ease integration of further API nodes
diff --git a/lib/Korap.pm b/lib/Korap.pm
index 13a44d1..a1025d9 100644
--- a/lib/Korap.pm
+++ b/lib/Korap.pm
@@ -8,7 +8,14 @@
my $self = shift;
$self->plugin('Config');
- $self->plugin('TagHelpers::Pagination');
+ $self->plugin('TagHelpers::Pagination' => {
+ prev => '<span><i class="fa fa-caret-left"></i></span>',
+ next => '<span><i class="fa fa-caret-right"></i></span>',
+ ellipsis => '<span>…</span>',
+ separator => '',
+ current => '<span>{current}</span>',
+ page => '<span>{page}</span>'
+ });
$self->plugin('Notifications');
$self->plugin('Number::Commify');
@@ -35,6 +42,10 @@
}
);
+ $r->get('/util/query')->to('search#query');
+
+ $r->get('/:resource' => [qw/collection corpus/])->to('search#info');
+
# resource => [qw/collection corpus/]
$r->get('/:resource')->search;
$r->get('/:resource/:cid', resource => [qw/collection corpus/])->search;
diff --git a/lib/Korap/Plugin/KorapSearch.pm b/lib/Korap/Plugin/KorapSearch.pm
index 72e6c9b..a6aaac1 100644
--- a/lib/Korap/Plugin/KorapSearch.pm
+++ b/lib/Korap/Plugin/KorapSearch.pm
@@ -68,6 +68,9 @@
$query{rctx} = 'chars';
$query{rctxs} = 120;
+ $query{cutoff} = $param{cutoff} // $c->param('cutoff');
+
+
$url->query(\%query);
$c->stash('search.totalResults' => 0);
diff --git a/lib/Korap/Search.pm b/lib/Korap/Search.pm
index e548ace..4773649 100644
--- a/lib/Korap/Search.pm
+++ b/lib/Korap/Search.pm
@@ -5,10 +5,44 @@
sub remote {
my $c = shift;
+ if ($c->param('action') eq 'inspect') {
+ my $api = $c->config('KorAP')->{api};
+ my $url = Mojo::URL->new($api)->path('resource/query');
+ $url->query({
+ q => scalar $c->param('q') // '',
+ ql => scalar $c->param('ql') // 'poliqarp'
+ });
+ if (my $response = $c->ua->get($url)->success) {
+ $c->stash('search.query' => $response->json);
+ }
+ else {
+ $c->notify(error => 'Unable to retrieve serialized query');
+ };
+
+ $c->param(cutoff => 1);
+ return $c->render(template => 'query', layout => 'default', title => 'KorAP');
+ };
+
# Render template "example/welcome.html.ep" with message
$c->render(template => 'search');
};
+sub info {
+ my $c = shift;
+ my $api = $c->config('KorAP')->{api};
+ my $src = $c->stash('resource');
+ $src = 'VirtualCollection' if $src eq 'collection';
+ $src = 'Corpus' if $src eq 'corpus';
+ my $url = Mojo::URL->new($api)->path('resource/' . $src);
+ if (my $response = $c->ua->get($url)->success) {
+ $c->render(json => $c->notifications(json => $response->json));
+ };
+};
1;
+
+
+__END__
+
+[{"id":1,"name":"Wikipedia","description":"Die freie Enzyklopädie","owner":0,"created":1401193381119,"managed":true,"shared":false,"foundries":"base;corenlp;mate;mpt;opennlp;tt;xip","refCorpus":"","query":"[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"WPD\"}}]","cache":false,"stats":"{\"documents\":196510,\"tokens\":51545081,\"sentences\":4116282,\"paragraphs\":2034752}"}]