diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f6ec714a656..912e601750f 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -71,6 +71,8 @@ Other
* LUCENE-7346: Update forbiddenapis to version 2.2.
(Uwe Schindler)
+
+* LUCENE-7360: Explanation.toHtml() is deprecated. (Alan Woodward)
======================= Lucene 6.1.0 =======================
diff --git a/lucene/core/src/java/org/apache/lucene/search/Explanation.java b/lucene/core/src/java/org/apache/lucene/search/Explanation.java
index 70bf8bc3271..3e5951a5a0f 100644
--- a/lucene/core/src/java/org/apache/lucene/search/Explanation.java
+++ b/lucene/core/src/java/org/apache/lucene/search/Explanation.java
@@ -123,6 +123,7 @@ public final class Explanation {
/** Render an explanation as HTML. */
+ @Deprecated
public String toHtml() {
StringBuilder buffer = new StringBuilder();
buffer.append("
\n");
diff --git a/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java
index 71e40941693..f9e1ec68cc7 100644
--- a/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java
+++ b/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java
@@ -70,6 +70,26 @@ public class ExplainAugmenterFactory extends TransformerFactory
return new ExplainAugmenter( field, style );
}
+ /** Render an explanation as HTML. */
+ public static String toHtml(Explanation explanation) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("\n");
+
+ buffer.append("- ");
+ buffer.append(explanation.getValue()).append(" = ").append(explanation.getDescription());
+ buffer.append("
\n");
+
+ Explanation[] details = explanation.getDetails();
+ for (int i = 0 ; i < details.length; i++) {
+ buffer.append(toHtml(details[i]));
+ }
+
+ buffer.append(" \n");
+ buffer.append("
\n");
+
+ return buffer.toString();
+ }
+
static class ExplainAugmenter extends DocTransformer {
final String name;
final Style style;
@@ -95,7 +115,7 @@ public class ExplainAugmenterFactory extends TransformerFactory
doc.setField( name, SolrPluginUtils.explanationToNamedList(exp) );
}
else if( style == Style.html ) {
- doc.setField( name, exp.toHtml() );
+ doc.setField( name, toHtml(exp));
}
else {
doc.setField( name, exp.toString() );