QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / beagled / Lucene.Net / Search / Explanation.cs
blob83c2033e7d6178042620935c5be1b7d17599faa3
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System;
19 namespace Lucene.Net.Search
22 /// <summary>Expert: Describes the score computation for document and query. </summary>
23 [Serializable]
24 public class Explanation
26 private float value_Renamed; // the value of this node
27 private System.String description; // what it represents
28 private System.Collections.ArrayList details; // sub-explanations
30 public Explanation()
34 public Explanation(float value_Renamed, System.String description)
36 this.value_Renamed = value_Renamed;
37 this.description = description;
40 /// <summary>The value assigned to this explanation node. </summary>
41 public virtual float GetValue()
43 return value_Renamed;
45 /// <summary>Sets the value assigned to this explanation node. </summary>
46 public virtual void SetValue(float value_Renamed)
48 this.value_Renamed = value_Renamed;
51 /// <summary>A description of this explanation node. </summary>
52 public virtual System.String GetDescription()
54 return description;
56 /// <summary>Sets the description of this explanation node. </summary>
57 public virtual void SetDescription(System.String description)
59 this.description = description;
62 /// <summary>The sub-nodes of this explanation node. </summary>
63 public virtual Explanation[] GetDetails()
65 if (details == null)
66 return null;
67 return (Explanation[]) details.ToArray(typeof(Explanation));
70 /// <summary>Adds a sub-node to this explanation node. </summary>
71 public virtual void AddDetail(Explanation detail)
73 if (details == null)
74 details = new System.Collections.ArrayList();
75 details.Add(detail);
78 /// <summary>Render an explanation as text. </summary>
79 public override System.String ToString()
81 return ToString(0);
83 private System.String ToString(int depth)
85 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
86 for (int i = 0; i < depth; i++)
88 buffer.Append(" ");
90 buffer.Append(GetValue());
91 buffer.Append(" = ");
92 buffer.Append(GetDescription());
93 buffer.Append("\n");
95 Explanation[] details = GetDetails();
96 if (details != null)
98 for (int i = 0; i < details.Length; i++)
100 buffer.Append(details[i].ToString(depth + 1));
104 return buffer.ToString();
108 /// <summary>Render an explanation as HTML. </summary>
109 public virtual System.String ToHtml()
111 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
112 buffer.Append("<ul>\n");
114 buffer.Append("<li>");
115 buffer.Append(GetValue());
116 buffer.Append(" = ");
117 buffer.Append(GetDescription());
118 buffer.Append("</li>\n");
120 Explanation[] details = GetDetails();
121 if (details != null)
123 for (int i = 0; i < details.Length; i++)
125 buffer.Append(details[i].ToHtml());
129 buffer.Append("</ul>\n");
131 return buffer.ToString();