blob: fd9e6d5a44653fef68c71251fbbc8ffd0ccbcc7f [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;
Nils Diewald2329e1d2014-06-12 16:07:57 +00007 $c->layout('default');
8 $c->title('KorAP');
Nils Diewald5d1ffb42014-05-21 17:45:34 +00009
Nils Diewald2329e1d2014-06-12 16:07:57 +000010 if ((scalar $c->param('action') // '') eq 'inspect') {
Nils Diewald02df9912014-06-03 16:08:07 +000011 my $api = $c->config('KorAP')->{api};
12 my $url = Mojo::URL->new($api)->path('resource/query');
13 $url->query({
14 q => scalar $c->param('q') // '',
15 ql => scalar $c->param('ql') // 'poliqarp'
16 });
17 if (my $response = $c->ua->get($url)->success) {
18 $c->stash('search.query' => $response->json);
19 }
20 else {
21 $c->notify(error => 'Unable to retrieve serialized query');
22 };
23
24 $c->param(cutoff => 1);
Nils Diewald2329e1d2014-06-12 16:07:57 +000025 return $c->render(template => 'query');
26 }
27
28 elsif ($c->param('snippet')) {
29 $c->layout('snippet');
Nils Diewald02df9912014-06-03 16:08:07 +000030 };
31
Nils Diewald5d1ffb42014-05-21 17:45:34 +000032 $c->render(template => 'search');
33};
34
Nils Diewald2329e1d2014-06-12 16:07:57 +000035
36
Nils Diewald02df9912014-06-03 16:08:07 +000037sub info {
38 my $c = shift;
39 my $api = $c->config('KorAP')->{api};
40 my $src = $c->stash('resource');
Nils Diewald2329e1d2014-06-12 16:07:57 +000041 $c->render(json => $c->notifications(json => $c->info_on($src)));
Nils Diewald02df9912014-06-03 16:08:07 +000042};
Nils Diewald5d1ffb42014-05-21 17:45:34 +000043
Nils Diewald2329e1d2014-06-12 16:07:57 +000044
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000451;
Nils Diewald02df9912014-06-03 16:08:07 +000046
47
48__END__
49
Nils Diewald2329e1d2014-06-12 16:07:57 +000050[{"shared":false,"id":1,"managed":true,"created":1401193381119,"stats":{"documents":196510,"tokens":51545081,"sentences":4116282,"paragraphs":2034752},"query":[{"@type":"korap:meta-filter","@value":{"@type":"korap:term","@field":"korap:field#corpusID","@value":"WPD"}}],"description":"Die freie Enzyklopädie","name":"Wikipedia","foundries":"base;corenlp;mate;mpt;opennlp;tt;xip"}]