blob: 47736491d2306bbb8baf0e5fc6e0a0a6de5a87f9 [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap::Search;
2use Mojo::Base 'Mojolicious::Controller';
3
4# This action will render a template
5sub remote {
6 my $c = shift;
7
Nils Diewald02df9912014-06-03 16:08:07 +00008 if ($c->param('action') eq 'inspect') {
9 my $api = $c->config('KorAP')->{api};
10 my $url = Mojo::URL->new($api)->path('resource/query');
11 $url->query({
12 q => scalar $c->param('q') // '',
13 ql => scalar $c->param('ql') // 'poliqarp'
14 });
15 if (my $response = $c->ua->get($url)->success) {
16 $c->stash('search.query' => $response->json);
17 }
18 else {
19 $c->notify(error => 'Unable to retrieve serialized query');
20 };
21
22 $c->param(cutoff => 1);
23 return $c->render(template => 'query', layout => 'default', title => 'KorAP');
24 };
25
Nils Diewald5d1ffb42014-05-21 17:45:34 +000026 # Render template "example/welcome.html.ep" with message
27 $c->render(template => 'search');
28};
29
Nils Diewald02df9912014-06-03 16:08:07 +000030sub info {
31 my $c = shift;
32 my $api = $c->config('KorAP')->{api};
33 my $src = $c->stash('resource');
34 $src = 'VirtualCollection' if $src eq 'collection';
35 $src = 'Corpus' if $src eq 'corpus';
Nils Diewald5d1ffb42014-05-21 17:45:34 +000036
Nils Diewald02df9912014-06-03 16:08:07 +000037 my $url = Mojo::URL->new($api)->path('resource/' . $src);
38 if (my $response = $c->ua->get($url)->success) {
39 $c->render(json => $c->notifications(json => $response->json));
40 };
41};
Nils Diewald5d1ffb42014-05-21 17:45:34 +000042
431;
Nils Diewald02df9912014-06-03 16:08:07 +000044
45
46__END__
47
48[{"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}"}]