Support configuration of query defaults

Change-Id: I04b2077d3b803795f070268687103c557d81606a
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index c93042f..e37b0d8 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -319,6 +319,18 @@
     };
   };
 
+  # 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) : [];
diff --git a/lib/Kalamar/Controller/Search.pm b/lib/Kalamar/Controller/Search.pm
index 54d1dc4..a14cadc 100644
--- a/lib/Kalamar/Controller/Search.pm
+++ b/lib/Kalamar/Controller/Search.pm
@@ -6,8 +6,6 @@
 use Mojo::JSON;
 use POSIX 'ceil';
 
-has items_per_page => 25;
-
 # TODO:
 #   Support server timing API
 #
@@ -90,21 +88,19 @@
     );
   };
 
+  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;
   };