Fix treatment of legacy 'collection' parameter

Change-Id: I12f985e52f839663eada211ba2e48e401764bc83
diff --git a/Changes b/Changes
index ad83167..48e9542 100755
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.36 2019-08-07
+0.36 2019-08-28
         - Rename all cookies to be independent
           for different instance (#94).
         - Enable https only via
@@ -7,6 +7,7 @@
         - Emit 'after_render' in proxy responses
           to make it accessible to post processing
           (such as the Piwik plugin).
+        - Fix treatment of legacy "collection" parameter.
 
         WARNING: This requires relogin for all users!
 
diff --git a/lib/Kalamar/Controller/Search.pm b/lib/Kalamar/Controller/Search.pm
index 331f78d..3a7b380 100644
--- a/lib/Kalamar/Controller/Search.pm
+++ b/lib/Kalamar/Controller/Search.pm
@@ -38,14 +38,16 @@
   # $v->optional('action'); # action 'inspect' is no longer valid
   # $v->optional('snippet');
 
-  my $cutoff = 0;
+  my $cutoff;
   if ($v->param('cutoff') && $v->param('cutoff') =~ /^1|true$/i) {
-    $cutoff = 1;
+    $cutoff = 'true';
   };
 
   # Deal with legacy collection
-  if ($v->param('collection')) {
+  my $cq = $v->param('cq');
+  if ($v->param('collection') && !defined $cq) {
     $c->param(cq => $v->param('collection'));
+    $cq = $v->param('collection');
   };
 
   # No query (Check ignoring validation)
@@ -75,9 +77,9 @@
 
 
   $query{count}   = $v->param('count') // $c->items_per_page;
-  $query{cq}      = $v->param('cq');
 
-  $query{cutoff}  = $v->param('cutoff');
+  $query{cq}      = $cq;
+  $query{cutoff}  = $cutoff;
   # Before: 'base/s:p'/'paragraph'
   $query{context} = $v->param('context') // '40-t,40-t';
 
@@ -163,6 +165,7 @@
 
         # There are results to remember
         if (!$cutoff &&
+              !$c->stash('no_cache') &&
               $json->{meta}->{totalResults} >= 0) {
 
           # Remove cutoff requirement again
diff --git a/t/query.t b/t/query.t
index 4532167..9fb1678 100644
--- a/t/query.t
+++ b/t/query.t
@@ -225,10 +225,13 @@
   ->text_is('#total-results', '> 4,274,841');
   ;
 
+$t->app->defaults(no_cache => 1);
+
 # Query with collection
 $t->get_ok('/?q=baum&collection=availability+%3D+%2FCC-BY.*%2F')
   ->status_is(200)
   ->element_exists("input#cq[value='availability = /CC-BY.*/']")
+  ->content_like(qr!\"availability\"!)
   ->text_is('#error','')
   ;
 
@@ -236,6 +239,7 @@
 $t->get_ok('/?q=baum&cq=availability+%3D+%2FCC-BY.*%2F')
   ->status_is(200)
   ->element_exists("input#cq[value='availability = /CC-BY.*/']")
+  ->content_like(qr!\"availability\"!)
   ->text_is('#error','')
   ;