FileDocCategorySizeDatePackage
Explanation.javaAPI DocApache Lucene 2.1.03772Wed Feb 14 10:46:40 GMT 2007org.apache.lucene.search

Explanation

public class Explanation extends Object implements Serializable
Expert: Describes the score computation for document and query.

Fields Summary
private float
value
private String
description
private ArrayList
details
Constructors Summary
public Explanation()

public Explanation(float value, String description)

    this.value = value;
    this.description = description;
  
Methods Summary
public voidaddDetail(org.apache.lucene.search.Explanation detail)
Adds a sub-node to this explanation node.

    if (details == null)
      details = new ArrayList();
    details.add(detail);
  
public java.lang.StringgetDescription()
A description of this explanation node.

 return description; 
public org.apache.lucene.search.Explanation[]getDetails()
The sub-nodes of this explanation node.

    if (details == null)
      return null;
    return (Explanation[])details.toArray(new Explanation[0]);
  
protected java.lang.StringgetSummary()
A short one line summary which should contain all high level information about this Explanation, without the "Details"

    return getValue() + " = " + getDescription();
  
public floatgetValue()
The value assigned to this explanation node.

 return value; 
public booleanisMatch()
Indicates wether or not this Explanation models a good match.

By default, an Explanation represents a "match" if the value is positive.

see
#getValue

    return (0.0f < getValue());
  
public voidsetDescription(java.lang.String description)
Sets the description of this explanation node.

    this.description = description;
  
public voidsetValue(float value)
Sets the value assigned to this explanation node.

 this.value = value; 
public java.lang.StringtoHtml()
Render an explanation as HTML.

    StringBuffer buffer = new StringBuffer();
    buffer.append("<ul>\n");

    buffer.append("<li>");
    buffer.append(getSummary());
    buffer.append("<br />\n");

    Explanation[] details = getDetails();
    if (details != null) {
      for (int i = 0 ; i < details.length; i++) {
        buffer.append(details[i].toHtml());
      }
    }

    buffer.append("</li>\n");
    buffer.append("</ul>\n");

    return buffer.toString();
  
public java.lang.StringtoString()
Render an explanation as text.

    return toString(0);
  
protected java.lang.StringtoString(int depth)

    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < depth; i++) {
      buffer.append("  ");
    }
    buffer.append(getSummary());
    buffer.append("\n");

    Explanation[] details = getDetails();
    if (details != null) {
      for (int i = 0 ; i < details.length; i++) {
        buffer.append(details[i].toString(depth+1));
      }
    }

    return buffer.toString();