Skip to content
Permalink
Browse files

Made snapshots size customizable in Solr snapshots response writer

  • Loading branch information...
luccioman committed Oct 13, 2018
1 parent 7a62fc0 commit f366f43d6b7ee73938b4e037567fe0569dd0c1e5
Showing with 22 additions and 3 deletions.
  1. +22 −3 source/net/yacy/cora/federate/solr/responsewriter/SnapshotImagesReponseWriter.java
@@ -8,6 +8,7 @@
import net.yacy.search.schema.CollectionSchema;

import org.apache.lucene.document.Document;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.QueryResponseWriter;
@@ -29,6 +30,12 @@
DEFAULT_FIELD_LIST.add(CollectionSchema.sku.getSolrFieldName());
}

/** Default width for each snapshot image */
private static final int DEFAULT_WIDTH = 256;

/** Default height for each snapshot image */
private static final int DEFAULT_HEIGTH = 256;

public SnapshotImagesReponseWriter() {
super();
}
@@ -50,8 +57,10 @@ public void write(final Writer writer, final SolrQueryRequest request, final Sol

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");
final SolrParams originalParams = request.getOriginalParams();

final int width = originalParams.getInt("width", DEFAULT_WIDTH);
final int heigth = originalParams.getInt("height", DEFAULT_HEIGTH);

DocList response = ((ResultContext) values.get("response")).getDocList();
final int sz = response.size();
@@ -63,7 +72,17 @@ public void write(final Writer writer, final SolrQueryRequest request, final Sol
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("<a href=\"");
writer.write(url);
writer.write("\"><img src=\"/api/snapshot.jpg?urlhash=");
writer.write(urlhash);
writer.write("&amp;width=");
writer.write(String.valueOf(width));
writer.write("&amp;height=");
writer.write(String.valueOf(heigth));
writer.write("\" alt=\"");
writer.write(url);
writer.write("\"></a>\n");
}
}

0 comments on commit f366f43

Please sign in to comment.
You can’t perform that action at this time.