2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 namespace Mono.Lucene.Net.Search
23 /// <summary>Expert: Describes the score computation for document and query. </summary>
25 public class Explanation
27 private float value_Renamed; // the value of this node
28 private System.String description; // what it represents
29 private System.Collections.ArrayList details; // sub-explanations
35 public Explanation(float value_Renamed, System.String description)
37 this.value_Renamed = value_Renamed;
38 this.description = description;
41 /// <summary> Indicates whether or not this Explanation models a good match.
44 /// By default, an Explanation represents a "match" if the value is positive.
47 /// <seealso cref="getValue">
49 public virtual bool IsMatch()
51 return (0.0f < GetValue());
56 /// <summary>The value assigned to this explanation node. </summary>
57 public virtual float GetValue()
61 /// <summary>Sets the value assigned to this explanation node. </summary>
62 public virtual void SetValue(float value_Renamed)
64 this.value_Renamed = value_Renamed;
67 /// <summary>A description of this explanation node. </summary>
68 public virtual System.String GetDescription()
72 /// <summary>Sets the description of this explanation node. </summary>
73 public virtual void SetDescription(System.String description)
75 this.description = description;
78 /// <summary> A short one line summary which should contain all high level
79 /// information about this Explanation, without the "Details"
81 protected internal virtual System.String GetSummary()
83 return GetValue() + " = " + GetDescription();
86 /// <summary>The sub-nodes of this explanation node. </summary>
87 public virtual Explanation[] GetDetails()
91 return (Explanation[]) details.ToArray(typeof(Explanation));
94 /// <summary>Adds a sub-node to this explanation node. </summary>
95 public virtual void AddDetail(Explanation detail)
98 details = new System.Collections.ArrayList();
102 /// <summary>Render an explanation as text. </summary>
103 public override System.String ToString()
107 public /*protected internal*/ virtual System.String ToString(int depth)
109 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
110 for (int i = 0; i < depth; i++)
114 buffer.Append(GetSummary());
117 Explanation[] details = GetDetails();
120 for (int i = 0; i < details.Length; i++)
122 buffer.Append(details[i].ToString(depth + 1));
126 return buffer.ToString();
130 /// <summary>Render an explanation as HTML. </summary>
131 public virtual System.String ToHtml()
133 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
134 buffer.Append("<ul>\n");
136 buffer.Append("<li>");
137 buffer.Append(GetSummary());
138 buffer.Append("<br />\n");
140 Explanation[] details = GetDetails();
143 for (int i = 0; i < details.Length; i++)
145 buffer.Append(details[i].ToHtml());
149 buffer.Append("</li>\n");
150 buffer.Append("</ul>\n");
152 return buffer.ToString();
155 /// <summary> Small Util class used to pass both an idf factor as well as an
156 /// explanation for that factor.
158 /// This class will likely be held on a {@link Weight}, so be aware
159 /// before storing any large or un-serializable fields.
163 public abstract class IDFExplanation
165 /// <returns> the idf factor
167 public abstract float GetIdf();
168 /// <summary> This should be calculated lazily if possible.
171 /// <returns> the explanation for the idf factor.
173 public abstract System.String Explain();