Establish 'after_search' hook

Change-Id: Iac65f683d49ee342680629b1637ebd8eb6f217d7
diff --git a/Changes b/Changes
index 924df47..8f24bb2 100755
--- a/Changes
+++ b/Changes
@@ -14,6 +14,7 @@
           configuration option 'experimental_proxy') and enable
           proxy by default.
         - Establish 'after_search_results' content part.
+        - Establish 'after_search' hook.
 
 0.37 2020-01-16
         - Removed deprecated 'kalamar_test_port' helper.
diff --git a/lib/Kalamar/Controller/Search.pm b/lib/Kalamar/Controller/Search.pm
index 7705d56..b1374ac 100644
--- a/lib/Kalamar/Controller/Search.pm
+++ b/lib/Kalamar/Controller/Search.pm
@@ -115,7 +115,6 @@
   # Create remote request URL
   my $url = Mojo::URL->new($c->korap->api);
   $url->path('search');
-  # $url->query(%query);
   $url->query(map { $_ => $query{$_}} sort keys %query);
 
   # In case the user is not known, it is assumed, the user is not logged in
@@ -244,13 +243,16 @@
       # TODO:
       #   scalar $v->param('snippet') ? 'snippet' : 'search';
 
+      # Set search results in stash
+      $c->stash(results => _map_matches($json->{matches}));
+      $c->stash(start_page => $page);
+      $c->stash(start_index => $json->{meta}->{startIndex});
+
+      # Emit after search hook
+      $c->app->plugins->emit_hook(after_search => $c);
+
       # Render result
-      return $c->render(
-        start_page => $page,
-        start_index => $json->{meta}->{startIndex},
-        results => _map_matches($json->{matches}),
-        template => 'search'
-      );
+      return $c->render(template => 'search');
     }
 
       # Deal with errors
diff --git a/t/query.t b/t/query.t
index 289cc2b..f228e57 100644
--- a/t/query.t
+++ b/t/query.t
@@ -242,7 +242,7 @@
   ;
 
 $t->app->hook(
-  before_dispatch => sub {
+  after_search => sub {
     my $c = shift;
     $c->content_for('after_search_results' => '<p id="special">Funny</p>');
   }