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; |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame^] | 7 | $c->layout('default'); |
| 8 | $c->title('KorAP'); |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 9 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame^] | 10 | if ((scalar $c->param('action') // '') eq 'inspect') { |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 11 | 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 Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame^] | 25 | return $c->render(template => 'query'); |
| 26 | } |
| 27 | |
| 28 | elsif ($c->param('snippet')) { |
| 29 | $c->layout('snippet'); |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 32 | $c->render(template => 'search'); |
| 33 | }; |
| 34 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame^] | 35 | |
| 36 | |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 37 | sub info { |
| 38 | my $c = shift; |
| 39 | my $api = $c->config('KorAP')->{api}; |
| 40 | my $src = $c->stash('resource'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame^] | 41 | $c->render(json => $c->notifications(json => $c->info_on($src))); |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 42 | }; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 43 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame^] | 44 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 45 | 1; |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 46 | |
| 47 | |
| 48 | __END__ |
| 49 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame^] | 50 | [{"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"}] |