Skip to content
Permalink
Browse files

Improved rendering of the Solr api relative url in the html writer

In order to have a consistent relative url when using either
/solr/select or /solr/collection1/select entry point.
  • Loading branch information...
luccioman committed Jul 24, 2018
1 parent bf4f320 commit 89c59814dafe202cbfe8e9c8c0123e9089493a35
Showing with 13 additions and 17 deletions.
  1. +13 −17 source/net/yacy/cora/federate/solr/responsewriter/HTMLResponseWriter.java
@@ -120,12 +120,15 @@ private void writeJSLicence(final Writer writer) throws IOException {
/**
* Append a link to the related Solr API.
* @param writer the output writer
* @param paramsList the original request parameters
* @param solrParams the original request parameters
* @param coreName the requested Solr core name
* @throws IOException when a write error occurred
*/
private void writeApiLink(final Writer writer, final NamedList<Object> paramsList, final String coreName) throws IOException {
final String xmlquery = dqp.matcher("../solr/select?" + SolrParams.toSolrParams(paramsList).toString() + "&core=" + coreName).replaceAll("%22");
private void writeApiLink(final Writer writer, final SolrParams solrParams, final String coreName) throws IOException {
final NamedList<Object> paramsList = solrParams.toNamedList();
paramsList.remove("wt");

final String xmlquery = dqp.matcher("select?" + SolrParams.toSolrParams(paramsList).toString() + "&core=" + coreName).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.</span></div>\n");
@@ -290,9 +293,6 @@ public void write(final Writer writer, final SolrQueryRequest request, final Sol

writeHtmlHead(writer);

NamedList<Object> paramsList = request.getOriginalParams().toNamedList();
paramsList.remove("wt");

final String coreName = request.getCore().getName();

final Object responseObj = rsp.getResponse();
@@ -304,7 +304,7 @@ public void write(final Writer writer, final SolrQueryRequest request, final Sol
*/
final SolrDocumentList docList = ((SolrDocumentList)responseObj);

writeSolrDocumentList(writer, request, rsp.getResponseHeader(), coreName, paramsList, docList);
writeSolrDocumentList(writer, request, rsp.getResponseHeader(), coreName, docList);
} else if(responseObj instanceof ResultContext){
/* Regular response object */
final DocList documents = ((ResultContext)responseObj).getDocList();
@@ -325,7 +325,7 @@ public void write(final Writer writer, final SolrQueryRequest request, final Sol

writeResponseHeader(writer, request, rsp.getResponseHeader());

writeApiLink(writer, paramsList, coreName);
writeApiLink(writer, request.getOriginalParams(), coreName);

writeDoc(writer, tdoc, coreName, rsp.getReturnFields());

@@ -360,14 +360,10 @@ public void write(final Writer writer, final SolrQueryRequest request, final Sol
public void write(final Writer writer, final SolrQueryRequest request, final String coreName, final QueryResponse rsp) throws IOException {
writeHtmlHead(writer);

final SolrParams originalParams = request.getOriginalParams();
final NamedList<Object> paramsList = originalParams.toNamedList();
paramsList.remove("wt");

final SolrDocumentList docsList = rsp.getResults();
final NamedList<Object> responseHeader = rsp.getHeader();

writeSolrDocumentList(writer, request, responseHeader, coreName, paramsList, docsList);
writeSolrDocumentList(writer, request, responseHeader, coreName, docsList);

writer.write("</body></html>\n");
}
@@ -378,12 +374,12 @@ public void write(final Writer writer, final SolrQueryRequest request, final Str
* @param request the initial Solr request
* @param responseHeader the eventual Solr response header
* @param coreName the requested Solr core
* @param paramsList the original request parameters
* @param docList the result Solr documents list
* @throws IOException
*/
private void writeSolrDocumentList(final Writer writer, final SolrQueryRequest request, final NamedList<Object> responseHeader, final String coreName,
final NamedList<Object> paramsList, final SolrDocumentList docList) throws IOException {
private void writeSolrDocumentList(final Writer writer, final SolrQueryRequest request,
final NamedList<Object> responseHeader, final String coreName, final SolrDocumentList docList)
throws IOException {
final int sz = docList.size();
if (sz > 0) {
final Iterator<SolrDocument> iterator = docList.iterator();
@@ -397,7 +393,7 @@ private void writeSolrDocumentList(final Writer writer, final SolrQueryRequest r

writeResponseHeader(writer, request, responseHeader);

writeApiLink(writer, paramsList, coreName);
writeApiLink(writer, request.getOriginalParams(), coreName);

writeDoc(writer, translateDoc(doc, fieldsToReturn), coreName, fieldsToReturn);

0 comments on commit 89c5981

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