Skip to content

Commit

Permalink
Support VCs via URL without queries (fixes #207)
Browse files Browse the repository at this point in the history
Change-Id: Idb8a8353f1128bbbd21b235a2e013ac4ab780661
  • Loading branch information
Akron committed Sep 23, 2024
1 parent 1689140 commit 9b82901
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
0.56 2024-08-28
0.56 2024-09-23
- Improve slim test for plugin support
(korapxml2...; diewald)
- Fix layerInfo retrieval for relation view. (diewald)
- Change look of addon logo. (diewald)
- Support VCs via URL without queries (diewald)

0.55 2024-07-03
- Removed deprecated doc_link_to helper. (diewald)
Expand Down
50 changes: 36 additions & 14 deletions lib/Kalamar/Controller/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Mojo::JSON;
use POSIX 'ceil';

our @search_fields = qw!ID UID textSigle layerInfos title subTitle pubDate author availability snippet!;
our $query_placeholder = 'NOQUERY';

# TODO:
# Support server timing API
Expand Down Expand Up @@ -58,27 +59,38 @@ sub query {
$cq = $v->param('collection');
};

my %query = ();
$query{q} = $v->param('q') // '';
$query{ql} = $v->param('ql') // 'poliqarp';

# No query (Check ignoring validation)
unless ($c->param('q')) {
return $c->render(
$c->loc('Template_intro', 'intro'),
robots => 'index,follow'
);

# No corpus query
unless ($v->param('cq')) {
return $c->render(
$c->loc('Template_intro', 'intro'),
robots => 'index,follow'
);
};

# Corpus query exists
$query{q} = $query_placeholder;
$query{count} = 0;
}

else {
$c->stash(title => $c->loc(
'searchtitle',
q => $query{'q'},
ql => $query{'ql'}
));
};

$c->res->headers->header('X-Robots', 'noindex');

my %query = ();
$query{q} = $v->param('q') // '';
$query{ql} = $v->param('ql') // 'poliqarp';

$c->stash(q => $query{q});
$c->stash(ql => $query{ql});
$c->stash(title => $c->loc(
'searchtitle',
q => $query{'q'},
ql => $query{'ql'}
));

# Check validation
if ($v->has_error) {
Expand All @@ -96,7 +108,6 @@ sub query {
my $items_per_page = $c->stash('items_per_page');

$query{count} = $v->param('count') // $items_per_page;

$query{cq} = $cq;
$query{cutoff} = $cutoff;
$query{context} = $v->param('context') // $c->stash('context');
Expand Down Expand Up @@ -269,6 +280,17 @@ sub query {
# Emit after search hook
$c->app->plugins->emit_hook(after_search => $c);

# Only corpus query is set
if ($c->stash('q') eq $query_placeholder) {
$c->stash(q => '');
$c->req->query_params->remove('q');
$c->req->query_params->remove('count');
return $c->render(
$c->loc('Template_intro', 'intro'),
robots => 'index,follow'
);
};

# Render result
return $c->render(template => 'search');
}
Expand Down
14 changes: 14 additions & 0 deletions t/intro.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ $t->get_ok('/')
->element_exists('meta[name="DC.description"][content="KorAP - Corpus Analysis Platform"]')
->element_exists('meta[name="keywords"][content^="KorAP"]')
->element_exists('body[itemscope][itemtype="http://schema.org/WebApplication"]')
->element_exists_not('#koralQuery')
;

$t->get_ok('/?cq=corpusSigle%3DGOE')
->status_is(200)
->text_is('title', 'KorAP - Corpus Analysis Platform')
->text_is('h1 span', 'KorAP - Corpus Analysis Platform')
->element_exists_not('#notifications div.notify')
->element_exists('div.intro')
->text_is('div.intro h2', 'This is a custom intro page!')
->element_exists('meta[name="DC.description"][content="KorAP - Corpus Analysis Platform"]')
->element_exists('meta[name="keywords"][content^="KorAP"]')
->element_exists('body[itemscope][itemtype="http://schema.org/WebApplication"]')
->element_exists('#koralQuery')
;

$t->get_ok('/huhuhuhuhu')
Expand Down
6 changes: 6 additions & 0 deletions t/server/mock.pl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@
);
};

if ($v->param('q') eq $Kalamar::Controller::Search::query_placeholder) {
# Get response based on query parameter
my $response = $c->load_response('query_baum_o0_c25_cq');
return $c->render(%$response);
};

my @slug_base = ($v->param('q'));
push @slug_base, 'o' . $v->param('offset') if defined $v->param('offset');
push @slug_base, 'c' . $v->param('count') if defined $v->param('count');
Expand Down
5 changes: 4 additions & 1 deletion templates/layouts/main.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
</noscript>

<main<% if (stash 'main_class') { %> class="<%= stash 'main_class' %>"<% } %>>
%= content

%= include 'query'

%= content
</main>

% unless ($embedded) {
Expand Down
2 changes: 0 additions & 2 deletions templates/search.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
</p>
</div>

%= include 'query'

<div id="search">
% if (stash('results')->size && stash('total_results') != 0) {
<ol class="align-left">
Expand Down

0 comments on commit 9b82901

Please sign in to comment.