Added an API retrieving fields of a virtual corpus.

Change-Id: I577e29bae1b3112ccb16a2d6b2c65d06695198c0
diff --git a/core/Changes b/core/Changes
index 056aed2..0662426 100644
--- a/core/Changes
+++ b/core/Changes
@@ -12,6 +12,8 @@
  - Bumped spring.version from 5.3.13 to 5.3.14
 2022-01-25
  - Added show-tokens option to the search API.
+2022-01-31
+ - Added an API retrieving fields of a virtual corpus.
 
 # version 0.64
 
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index 27665a2..2eb98ab 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -12,6 +12,8 @@
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.store.MMapDirectory;
 
+import com.fasterxml.jackson.databind.JsonNode;
+
 import de.ids_mannheim.korap.Krill;
 import de.ids_mannheim.korap.KrillCollection;
 import de.ids_mannheim.korap.KrillIndex;
@@ -60,11 +62,13 @@
         };
     };
 
+
     public KrillIndex getIndex () {
         return index;
     };
-    
-    public void closeIndexReader() throws KustvaktException{
+
+
+    public void closeIndexReader () throws KustvaktException {
         try {
             index.closeReader();
         }
@@ -73,6 +77,7 @@
         }
     }
 
+
     /**
      * Search in the Lucene index.
      * 
@@ -96,6 +101,7 @@
         return kr.toJsonString();
     };
 
+
     /**
      * Search in the Lucene index and return matches as token lists.
      * 
@@ -115,6 +121,7 @@
         return kr.toJsonString();
     };
 
+
     /**
      * Get info on a match - by means of a richly annotated html
      * snippet.
@@ -124,7 +131,8 @@
      * @param availabilityList
      * @throws KustvaktException
      */
-    public String getMatch (String id, Pattern licensePattern) throws KustvaktException {
+    public String getMatch (String id, Pattern licensePattern)
+            throws KustvaktException {
         Match km;
         if (index != null) {
             try {
@@ -144,6 +152,7 @@
         return km.toJsonString();
     };
 
+
     private void checkAvailability (Pattern licensePattern, String availability,
             String id) throws KustvaktException {
         if (DEBUG) {
@@ -165,12 +174,13 @@
         }
 
     }
-    
+
+
     /*
      * Retrieve the meta fields for a certain document
      */
-    public String getFields (String id, List<String> fields, Pattern licensePattern)
-            throws KustvaktException {
+    public String getFields (String id, List<String> fields,
+            Pattern licensePattern) throws KustvaktException {
         MetaFields meta;
 
         // No index found
@@ -180,7 +190,7 @@
         }
 
         // Index available
-        else if (fields !=null){
+        else if (fields != null) {
             // Get fields
             meta = index.getFields(id, fields);
         }
@@ -188,7 +198,7 @@
             // Get fields
             meta = index.getFields(id);
         }
-        
+
         // EM: this approach forbids the whole metadata
         // this should be refined by filtering out only the restricted
         // metadata fields
@@ -197,7 +207,7 @@
 
         return meta.toJsonString();
     };
-    
+
 
     public String getMatch (String id, List<String> foundries,
             List<String> layers, boolean includeSpans,
@@ -223,6 +233,7 @@
         return km.toJsonString();
     };
 
+
     /**
      * Get info on a match - by means of a richly annotated html
      * snippet.
@@ -270,6 +281,7 @@
         return km.toJsonString();
     };
 
+
     /**
      * Get statistics on (virtual) collections.
      * 
@@ -277,7 +289,7 @@
      * 
      * @param json
      *            JSON-LD string with potential meta filters.
-     * @throws KustvaktException 
+     * @throws KustvaktException
      */
     public String getStatistics (String json) throws KustvaktException {
         if (index == null) {
@@ -317,7 +329,7 @@
         catch (IOException e) {
             e.printStackTrace();
         };
-        
+
         if (kc.hasErrors()) {
             throw new KustvaktException(
                     "{\"errors\":" + kc.getErrors().toJsonString() + "}");
@@ -330,6 +342,7 @@
         return sb.toString();
     };
 
+
     /**
      * Return the match identifier as a string.
      * This is a convenient method to deal with legacy instantiation
@@ -345,6 +358,7 @@
         return sb.toString();
     };
 
+
     /**
      * Return the text sigle as a string.
      */
@@ -356,14 +370,20 @@
         return sb.toString();
     };
 
+
     /**
      * Return the fingerprint of the latest index revision.
      */
-    public String getIndexFingerprint() {
+    public String getIndexFingerprint () {
         if (index != null) {
             return index.getFingerprint();
         };
         return "null";
     }
 
+
+    public JsonNode getFieldValuesForVC (String koralQuery, String fieldName) {
+        return new Krill().retrieveFieldValues(koralQuery, index, fieldName);
+    }
+
 };