Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 1 | package Korap::Search; |
| 2 | use Mojo::Base 'Mojolicious::Controller'; |
| 3 | |
| 4 | # This action will render a template |
| 5 | sub remote { |
| 6 | my $c = shift; |
| 7 | |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame^] | 8 | 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 Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 26 | # Render template "example/welcome.html.ep" with message |
| 27 | $c->render(template => 'search'); |
| 28 | }; |
| 29 | |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame^] | 30 | sub 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 Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 36 | |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame^] | 37 | 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 Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 42 | |
| 43 | 1; |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame^] | 44 | |
| 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}"}] |