Skip to content

Apache Lucene open-source search software

SOLR-2417 -- by default spit out the explain text as string, but allow NL or HTML

Ryan McKinleyad221cb51456
diff --git a/solr/src/java/org/apache/solr/response/transform/ExplainAugmenter.java b/solr/src/java/org/apache/solr/response/transform/ExplainAugmenter.java
index 0b354a2c1a3..122047e13ca 100644
--- a/solr/src/java/org/apache/solr/response/transform/ExplainAugmenter.java
+++ b/solr/src/java/org/apache/solr/response/transform/ExplainAugmenter.java
@@ -32,12 +32,24 @@ import org.slf4j.LoggerFactory;
*/
public class ExplainAugmenter extends TransformerWithContext
{
- static final Logger log = LoggerFactory.getLogger( ExplainAugmenter.class );
+ static enum Style {
+ NL,
+ TEXT,
+ HTML
+ };
+
final String name;
-
+ final Style style;
+
public ExplainAugmenter( String display )
+ {
+ this( display, Style.TEXT );
+ }
+
+ public ExplainAugmenter( String display, Style style )
{
this.name = display;
+ this.style = style;
}
@Override
@@ -45,7 +57,15 @@ public class ExplainAugmenter extends TransformerWithContext
if( context != null && context.query != null ) {
try {
Explanation exp = context.searcher.explain(context.query, docid);
- doc.setField( name, SolrPluginUtils.explanationToNamedList(exp) );
+ if( style == Style.NL ) {
+ doc.setField( name, SolrPluginUtils.explanationToNamedList(exp) );
+ }
+ else if( style == Style.NL ) {
+ doc.setField( name, exp.toHtml() );
+ }
+ else {
+ doc.setField( name, exp.toString() );
+ }
}
catch (IOException e) {
e.printStackTrace();