fix html header in Solr HTMLResponseWriter

- move 1st body content after </head> tag
- add closing <span> tag
pull/1/head
reger 11 years ago
parent a09e70cd68
commit 3d5d366f1c

@ -89,32 +89,35 @@ public class HTMLResponseWriter implements QueryResponseWriter {
NamedList<Object> paramsList = request.getOriginalParams().toNamedList(); NamedList<Object> paramsList = request.getOriginalParams().toNamedList();
paramsList.remove("wt"); paramsList.remove("wt");
String xmlquery = dqp.matcher("/solr/select?" + SolrParams.toSolrParams(paramsList).toString()).replaceAll("%22"); String xmlquery = dqp.matcher("/solr/select?" + SolrParams.toSolrParams(paramsList).toString()).replaceAll("%22");
writer.write("<div id=\"api\"><a href=\"" + xmlquery + "\"><img src=\"../env/grafics/api.png\" width=\"60\" height=\"40\" alt=\"API\" /></a>\n");
writer.write("<span>This search result can also be retrieved as XML. Click the API icon to see this page as XML.</div>\n");
DocList response = ((ResultContext) values.get("response")).docs; DocList response = ((ResultContext) values.get("response")).docs;
final int sz = response.size(); final int sz = response.size();
if (sz > 0) { if (sz > 0) {
SolrIndexSearcher searcher = request.getSearcher(); SolrIndexSearcher searcher = request.getSearcher();
DocIterator iterator = response.iterator(); DocIterator iterator = response.iterator();
IndexSchema schema = request.getSchema(); IndexSchema schema = request.getSchema();
int id = iterator.nextDoc();
Document doc = searcher.doc(id, DEFAULT_FIELD_LIST);
LinkedHashMap<String, String> tdoc = translateDoc(schema, doc);
String title = tdoc.get(CollectionSchema.title.getSolrFieldName());
if (sz == 1) { if (sz == 1) {
int id = iterator.nextDoc();
Document doc = searcher.doc(id, DEFAULT_FIELD_LIST);
LinkedHashMap<String, String> tdoc = translateDoc(schema, doc);
String title = tdoc.get(CollectionSchema.title.getSolrFieldName());
writer.write("<title>" + title + "</title>\n</head><body>\n"); writer.write("<title>" + title + "</title>\n</head><body>\n");
writeDoc(writer, tdoc, title);
} else { } else {
writer.write("<title>Document List</title>\n</head><body>\n"); writer.write("<title>Document List</title>\n</head><body>\n");
for (int i = 0; i < sz; i++) { }
int id = iterator.nextDoc(); writer.write("<div id=\"api\"><a href=\"" + xmlquery + "\"><img src=\"../env/grafics/api.png\" width=\"60\" height=\"40\" alt=\"API\" /></a>\n");
Document doc = searcher.doc(id, DEFAULT_FIELD_LIST); writer.write("<span>This search result can also be retrieved as XML. Click the API icon to see this page as XML.</span></div>\n");
LinkedHashMap<String, String> tdoc = translateDoc(schema, doc);
String title = tdoc.get(CollectionSchema.title.getSolrFieldName()); writeDoc(writer, tdoc, title);
writeDoc(writer, tdoc, title);
} while (iterator.hasNext()) {
id = iterator.nextDoc();
doc = searcher.doc(id, DEFAULT_FIELD_LIST);
tdoc = translateDoc(schema, doc);
title = tdoc.get(CollectionSchema.title.getSolrFieldName());
writeDoc(writer, tdoc, title);
} }
} else { } else {
writer.write("<title>No Document Found</title>\n</head><body>\n"); writer.write("<title>No Document Found</title>\n</head><body>\n");

Loading…
Cancel
Save