Skip to content

Commit

Permalink
Support configuration of query defaults
Browse files Browse the repository at this point in the history
Change-Id: I04b2077d3b803795f070268687103c557d81606a
  • Loading branch information
Akron committed May 14, 2024
1 parent 7b98f26 commit 3422d45
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0.53 2024-03-15
0.53 2024-05-14
- Add openapi url to documentation. (hebasta)
- Solve a potential timing issue in VC rendering. (diewald)
- Update DeReKo link in corpus specific localization. (hebasta)
Expand All @@ -7,6 +7,8 @@
- Fix: The content of blockquote is displayed. (hebasta)
- Upgrade dependency and remove deprecated
method. (diewald)
- Add configuration option for defaults: items_per_page, context.
(diewald)

0.52 2023-11-29
- Update Piwik dependency to point to matomo.js. (diewald)
Expand Down
6 changes: 6 additions & 0 deletions kalamar.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,11 @@
## Set proxy timeouts
# proxy_inactivity_timeout => 120,
# proxy_connect_timeout => 120,

## Adjust defaults
# defaults => {
# items_per_page => 20,
# context => '20-t,20-t'
# }
}
}
12 changes: 12 additions & 0 deletions lib/Kalamar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ sub startup {
};
};

# Set defaults per config
$self->defaults(
items_per_page => 25,
context => '40-t,40-t', # Before: 'base/s:p'/'paragraph'
);

if (exists $conf->{defaults}) {
my $def = $conf->{defaults};
$self->defaults(items_per_page => $def->{items_per_page}) if $def->{items_per_page};
$self->defaults(context => $def->{context}) if $def->{context};
};

# Configure documentation navigation
my $doc_navi = Mojo::File->new($self->home->child('templates','doc','navigation.json'))->slurp;
$doc_navi = $doc_navi ? decode_json($doc_navi) : [];
Expand Down
12 changes: 4 additions & 8 deletions lib/Kalamar/Controller/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use Mojo::Util qw/quote/;
use Mojo::JSON;
use POSIX 'ceil';

has items_per_page => 25;

# TODO:
# Support server timing API
#
Expand Down Expand Up @@ -90,21 +88,19 @@ sub query {
);
};

my $items_per_page = $c->stash('items_per_page');

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

$query{cq} = $cq;
$query{cutoff} = $cutoff;
# Before: 'base/s:p'/'paragraph'
$query{context} = $v->param('context') // '40-t,40-t';
$query{context} = $v->param('context') // $c->stash('context');

# Start page
my $page = $v->param('p') // 1;

my $items_per_page = $c->items_per_page;

# Set count
if ($query{count} && $query{count} <= $c->items_per_page ) {
if ($query{count} && $query{count} <= $items_per_page ) {
$items_per_page = delete $query{count};
$query{count} = $items_per_page;
};
Expand Down
77 changes: 77 additions & 0 deletions t/fixtures/response_query_baum_o0_c20_cotrue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"status" : 200,
"json" : {
"@context" : "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
"meta" : {
"count" : 20,
"startIndex" : 0,
"cutOff": true,
"authorized" : null,
"timeout" : 120000,
"context" : {
"left" : ["token",40],
"right" : ["token",40]
},
"fields" : ["pubDate","subTitle","author","pubPlace","title","textSigle","UID","ID","layerInfos","corpusSigle","docSigle","corpusID","textClass"],
"version" : "0.55.7",
"benchmark" : "0.120577834 s",
"totalResults" : -1,
"serialQuery" : "tokens:s:Baum",
"itemsPerPage" : 20
},
"query" : {
"@type" : "koral:token",
"wrap" : {
"@type" : "koral:term",
"layer" : "orth",
"key" : "Baum",
"match" : "match:eq",
"foundry" : "opennlp",
"rewrites" : [
{
"@type" : "koral:rewrite",
"src" : "Kustvakt",
"operation" : "operation:injection",
"scope" : "foundry"
}
]
}
},
"matches" : [
{
"field" : "tokens",
"pubPlace" : "München",
"textSigle" : "GOE/AGI/00000",
"docSigle" : "GOE/AGI",
"corpusSigle" : "GOE",
"title" : "Italienische Reise",
"subTitle" : "Auch ich in Arkadien!",
"author" : "Goethe, Johann Wolfgang von",
"layerInfos" : "base/s=spans corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels mdp/d=rels opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans",
"startMore" : true,
"endMore" : true,
"snippet" : "<span class=\"context-left\"><span class=\"more\"></span>sie etwas bedeuten zu wollen und machte mit der Oberlippe eine fatale Miene. ich sprach sehr viel mit ihr durch, sie war überall zu Hause und merkte gut auf die Gegenstände. so fragte sie mich einmal, was das für ein </span><span class=\"match\"><mark>Baum</mark></span><span class=\"context-right\"> sei. es war ein schöner großer Ahorn, der erste, der mir auf der ganzen Reise zu Gesichte kam. den hatte sie doch gleich bemerkt und freute sich, da mehrere nach und nach erschienen, daß sie auch diesen Baum unterscheiden könne<span class=\"more\"></span></span>",
"matchID" : "match-GOE/AGI/00000-p2030-2031",
"UID" : 0,
"pubDate" : "1982"
},
{
"field" : "tokens",
"pubPlace" : "München",
"textSigle" : "GOE/AGI/00001",
"docSigle" : "GOE/AGI",
"corpusSigle" : "GOE",
"title" : "Italienische Reise",
"subTitle" : "Auch ich in Arkadien!",
"author" : "Goethe, Johann Wolfgang von",
"layerInfos" : "base/s=spans corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels mdp/d=rels opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans",
"startMore" : true,
"endMore" : true,
"snippet" : "<span class=\"context-left\"><span class=\"more\"></span>für ein Baum sei. es war ein schöner großer Ahorn, der erste, der mir auf der ganzen Reise zu Gesichte kam. den hatte sie doch gleich bemerkt und freute sich, da mehrere nach und nach erschienen, daß sie auch diesen </span><span class=\"match\"><mark>Baum</mark></span><span class=\"context-right\"> unterscheiden könne. sie gehe, sagte sie, nach Bozen auf die Messe, wo ich doch wahrscheinlich auch hinzöge. wenn sie mich dort anträfe, müsse ich ihr einen Jahrmarkt kaufen, welches ich ihr denn auch versprach. dort wollte sie auch ihre neue<span class=\"more\"></span></span>",
"matchID" : "match-GOE/AGI/00000-p2068-2069",
"UID" : 0,
"pubDate" : "1982"
}
]
}
}
14 changes: 14 additions & 0 deletions t/query.t
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,22 @@ my $err = $t->get_ok('/?q=baum')
->attr_is('#pagination','data-count','25')
->tx->res->dom->at('#error')
;

is(defined $err ? $err->text : '', '');

# Query passed
$t->app->defaults(items_per_page => 20);

$t->get_ok('/?q=baum')
->status_is(200)
->content_type_is('text/html;charset=UTF-8')
->element_count_is('#pagination > a', 5)
->attr_is('#pagination','data-page','1')
->attr_is('#pagination','data-total','3')
->attr_is('#pagination','data-count','20')
;

$t->app->defaults(items_per_page => 25);

$t->get_ok('/?q=[orth=das')
->status_is(400)
Expand Down

0 comments on commit 3422d45

Please sign in to comment.