diff --git a/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java b/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java
index af6e50c72..6718b9b8e 100644
--- a/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java
+++ b/source/net/yacy/cora/federate/solr/responsewriter/GSAResponseWriter.java
@@ -25,20 +25,24 @@ import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.time.DateTimeException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexableField;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.XML;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.QueryResponseWriter;
@@ -61,7 +65,7 @@ import net.yacy.search.schema.CollectionSchema;
* example: GET /gsa/searchresult?q=chicken+teriyaki&output=xml&client=test&site=test&sort=date:D:S:d1
* for a xml reference, see https://developers.google.com/search-appliance/documentation/614/xml_reference
*/
-public class GSAResponseWriter implements QueryResponseWriter, EmbeddedSolrResponseWriter {
+public class GSAResponseWriter implements QueryResponseWriter, SolrjResponseWriter {
private static String YaCyVer = null;
private static final char lb = '\n';
@@ -86,9 +90,6 @@ public class GSAResponseWriter implements QueryResponseWriter, EmbeddedSolrRespo
"\n\n\n").toCharArray();
private static final char[] XML_STOP = "\n".toCharArray();
- // define a list of simple YaCySchema -> RSS Token matchings
- private static final Map field2tag = new HashMap();
-
// pre-select a set of YaCy schema fields for the solr searcher which should cause a better caching
private static final CollectionSchema[] extrafields = new CollectionSchema[]{
CollectionSchema.id, CollectionSchema.sku, CollectionSchema.title, CollectionSchema.description_txt,
@@ -96,15 +97,16 @@ public class GSAResponseWriter implements QueryResponseWriter, EmbeddedSolrRespo
CollectionSchema.language_s, CollectionSchema.collection_sxt
};
- private static final Set SOLR_FIELDS = new HashSet();
+ private static final Set SOLR_FIELDS = new HashSet<>();
static {
- field2tag.put(CollectionSchema.language_s.getSolrFieldName(), GSAToken.LANG.name());
- SOLR_FIELDS.addAll(field2tag.keySet());
+
+ SOLR_FIELDS.add(CollectionSchema.language_s.getSolrFieldName());
for (CollectionSchema field: extrafields) SOLR_FIELDS.add(field.getSolrFieldName());
}
private static class ResHead {
- public int offset, rows, numFound;
+ public long offset, numFound;
+ public int rows;
//public int status, QTime;
//public String df, q, wt;
//public float maxScore;
@@ -129,10 +131,6 @@ public class GSAResponseWriter implements QueryResponseWriter, EmbeddedSolrRespo
}
}
- public GSAResponseWriter() {
- super();
- }
-
@Override
public String getContentType(final SolrQueryRequest request, final SolrQueryResponse response) {
return CONTENT_TYPE_XML_UTF8;
@@ -144,41 +142,150 @@ public class GSAResponseWriter implements QueryResponseWriter, EmbeddedSolrRespo
@Override
public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp) throws IOException {
- assert rsp.getValues().get("responseHeader") != null;
- assert rsp.getValues().get("response") != null;
- long start = System.currentTimeMillis();
+ final long start = System.currentTimeMillis();
+
+ final Object responseObj = rsp.getResponse();
+
+ if(responseObj instanceof ResultContext) {
+ /* Regular response object */
+
+ final DocList documents = ((ResultContext) responseObj).getDocList();
+
+ final Object highlightingObj = rsp.getValues().get("highlighting");
+ final Map> snippets = highlightingObj instanceof NamedList
+ ? OpensearchResponseWriter.snippetsFromHighlighting((NamedList>) highlightingObj)
+ : new HashMap<>();
+
+ // parse response header
+ final ResHead resHead = new ResHead();
+ resHead.rows = request.getParams().getInt(CommonParams.ROWS, 0);
+ resHead.offset = documents.offset(); // equal to 'start'
+ resHead.numFound = documents.matches();
+ //resHead.df = (String) val0.get("df");
+ //resHead.q = (String) val0.get("q");
+ //resHead.wt = (String) val0.get("wt");
+ //resHead.status = (Integer) responseHeader.get("status");
+ //resHead.QTime = (Integer) responseHeader.get("QTime");
+ //resHead.maxScore = response.maxScore();
- SimpleOrderedMap