LUCENE-7360: Explanation.toHtml() is deprecated

This commit is contained in:
Alan Woodward 2016-06-29 09:08:16 +01:00
parent 4070bdd8d8
commit 23119db360
3 changed files with 24 additions and 1 deletions

View File

@ -81,6 +81,8 @@ Other
* LUCENE-7346: Update forbiddenapis to version 2.2.
(Uwe Schindler)
* LUCENE-7360: Explanation.toHtml() is deprecated. (Alan Woodward)
======================= Lucene 6.1.0 =======================

View File

@ -123,6 +123,7 @@ public final class Explanation {
/** Render an explanation as HTML. */
@Deprecated
public String toHtml() {
StringBuilder buffer = new StringBuilder();
buffer.append("<ul>\n");

View File

@ -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("<ul>\n");
buffer.append("<li>");
buffer.append(explanation.getValue()).append(" = ").append(explanation.getDescription());
buffer.append("<br />\n");
Explanation[] details = explanation.getDetails();
for (int i = 0 ; i < details.length; i++) {
buffer.append(toHtml(details[i]));
}
buffer.append("</li>\n");
buffer.append("</ul>\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() );