added (very experimental) Solr response writer for snapshot image

results
pull/1/head
Michael Peter Christen 10 years ago
parent 7287dd764e
commit 1cfddea578

@ -52,7 +52,7 @@ import org.apache.solr.search.SolrIndexSearcher;
public class HTMLResponseWriter implements QueryResponseWriter {
private static final Set<String> DEFAULT_FIELD_LIST = null;
private static final Pattern dqp = Pattern.compile("\"");
public static final Pattern dqp = Pattern.compile("\"");
public HTMLResponseWriter() {
super();
@ -180,7 +180,7 @@ public class HTMLResponseWriter implements QueryResponseWriter {
writer.write("</form>\n");
}
static final LinkedHashMap<String, String> translateDoc(final IndexSchema schema, final Document doc) {
public static final LinkedHashMap<String, String> translateDoc(final IndexSchema schema, final Document doc) {
List<IndexableField> fields = doc.getFields();
int sz = fields.size();
int fidx1 = 0, fidx2 = 0;

@ -0,0 +1,74 @@
package net.yacy.cora.federate.solr.responsewriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashSet;
import java.util.Set;
import net.yacy.search.schema.CollectionSchema;
import org.apache.lucene.document.Document;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.QueryResponseWriter;
import org.apache.solr.response.ResultContext;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.DocIterator;
import org.apache.solr.search.DocList;
import org.apache.solr.search.SolrIndexSearcher;
/**
* this writer is supposed to be used to generate iframes. It generates links for the /api/snapshot.jpg servlet.
*/
public class SnapshotImagesReponseWriter implements QueryResponseWriter {
private static final Set<String> DEFAULT_FIELD_LIST = new HashSet<>();
static {
DEFAULT_FIELD_LIST.add(CollectionSchema.id.getSolrFieldName());
DEFAULT_FIELD_LIST.add(CollectionSchema.sku.getSolrFieldName());
}
public SnapshotImagesReponseWriter() {
super();
}
@Override
public String getContentType(SolrQueryRequest arg0, SolrQueryResponse arg1) {
return "text/html";
}
@Override
public void init(@SuppressWarnings("rawtypes") NamedList n) {
}
@Override
public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp) throws IOException {
NamedList<?> values = rsp.getValues();
assert values.get("responseHeader") != null;
assert values.get("response") != null;
writer.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
writer.write("<head></head><body>\n");
NamedList<Object> paramsList = request.getOriginalParams().toNamedList();
paramsList.remove("wt");
DocList response = ((ResultContext) values.get("response")).docs;
final int sz = response.size();
if (sz > 0) {
SolrIndexSearcher searcher = request.getSearcher();
DocIterator iterator = response.iterator();
while (iterator.hasNext()) {
int id = iterator.nextDoc();
Document doc = searcher.doc(id, DEFAULT_FIELD_LIST);
String urlhash = doc.getField(CollectionSchema.id.getSolrFieldName()).stringValue();
String url = doc.getField(CollectionSchema.sku.getSolrFieldName()).stringValue();
writer.write("<a href=\"" + url + "\"><img src=\"/api/snapshot.jpg?urlhash=" + urlhash + "&amp;width=256&amp;height=256\" alt=\"" + url + "\"></a>\n");
}
}
writer.write("</body></html>\n");
}
}

@ -49,6 +49,7 @@ import net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter;
import net.yacy.cora.federate.solr.responsewriter.GrepHTMLResponseWriter;
import net.yacy.cora.federate.solr.responsewriter.HTMLResponseWriter;
import net.yacy.cora.federate.solr.responsewriter.OpensearchResponseWriter;
import net.yacy.cora.federate.solr.responsewriter.SnapshotImagesReponseWriter;
import net.yacy.cora.federate.solr.responsewriter.YJsonResponseWriter;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
@ -98,6 +99,7 @@ public class SolrSelectServlet extends HttpServlet {
RESPONSE_WRITER.put("xslt", xsltWriter); // try i.e. http://localhost:8090/solr/select?q=*:*&start=0&rows=10&wt=xslt&tr=json.xsl
RESPONSE_WRITER.put("exml", new EnhancedXMLResponseWriter());
RESPONSE_WRITER.put("html", new HTMLResponseWriter());
RESPONSE_WRITER.put("snapshots", new SnapshotImagesReponseWriter());
RESPONSE_WRITER.put("grephtml", new GrepHTMLResponseWriter());
RESPONSE_WRITER.put("rss", opensearchResponseWriter); //try http://localhost:8090/solr/select?wt=rss&q=olympia&hl=true&hl.fl=text_t,h1,h2
RESPONSE_WRITER.put("opensearch", opensearchResponseWriter); //try http://localhost:8090/solr/select?wt=rss&q=olympia&hl=true&hl.fl=text_t,h1,h2

Loading…
Cancel
Save