Addded a no-need-for-rewrite test.

Change-Id: I4441689d7534d79deb37ec357948bf6a6769433f
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java
index d69538e..189cdd5 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java
@@ -3,7 +3,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.regex.Matcher;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -17,7 +16,6 @@
 import de.ids_mannheim.korap.query.object.KoralMatchOperator;
 import de.ids_mannheim.korap.resource.rewrite.KoralNode.RewriteIdentifier;
 import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.user.User.CorpusAccess;
 import de.ids_mannheim.korap.utils.JsonUtils;
 import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
 
@@ -93,10 +91,10 @@
             userAvailabilities = checkAvailability(jsonNode.at("/collection"), userAvailabilities);
             if (!userAvailabilities.isEmpty()){
                 builder.with(buildAvailability(userAvailabilities));
+                builder.setBaseQuery(builder.toJSON());
+                rewrittesNode = builder.mergeWith(jsonNode).at("/collection");
+                node.set("collection", rewrittesNode, identifier);
             }
-            builder.setBaseQuery(builder.toJSON());
-            rewrittesNode = builder.mergeWith(jsonNode).at("/collection");
-            node.set("collection", rewrittesNode, identifier);
         }
         else {
             builder.with(buildAvailability(userAvailabilities));
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
index 407dcf0..e8d169a 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
@@ -224,9 +224,34 @@
         checkAndFree(response.getEntity(String.class));
     }
 
+    @Test
+    public void testAvailabilityRegexNoRewrite () {
+        ClientResponse response = builtSimpleClientResponse(
+                "availability = /CC-BY.*/ & availability = /ACA.*/");
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+
+        String json = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(json);
+        assertEquals("operation:and",
+                node.at("/collection/operation").asText());
+        assertEquals("match:eq",
+                node.at("/collection/operands/0/match").asText());
+        assertEquals("type:regex",
+                node.at("/collection/operands/0/type").asText());
+        assertEquals("availability",
+                node.at("/collection/operands/0/key").asText());
+        assertEquals("CC-BY.*",
+                node.at("/collection/operands/0/value").asText());
+        assertEquals("match:eq",
+                node.at("/collection/operands/1/match").asText());
+        assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
+        
+    }
+
 
     @Test
-    public void testAvailabilityRegexFreeUnauthorized2 () {
+    public void testAvailabilityRegexFreeUnauthorized3 () {
         ClientResponse response = builtSimpleClientResponse(
                 "availability = /.*NC.*/");
         assertEquals(ClientResponse.Status.OK.getStatusCode(),