Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Search / Explanation.cs
blob9f2094f4c4211830697693971310dfbdc1164be0
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.
16 using System;
17 namespace Lucene.Net.Search
20 /// <summary>Expert: Describes the score computation for document and query. </summary>
21 [Serializable]
22 public class Explanation
24 private float value_Renamed; // the value of this node
25 private System.String description; // what it represents
26 private System.Collections.ArrayList details; // sub-explanations
28 public Explanation()
32 public Explanation(float value_Renamed, System.String description)
34 this.value_Renamed = value_Renamed;
35 this.description = description;
38 /// <summary>The value assigned to this explanation node. </summary>
39 public virtual float GetValue()
41 return value_Renamed;
43 /// <summary>Sets the value assigned to this explanation node. </summary>
44 public virtual void SetValue(float value_Renamed)
46 this.value_Renamed = value_Renamed;
49 /// <summary>A description of this explanation node. </summary>
50 public virtual System.String GetDescription()
52 return description;
54 /// <summary>Sets the description of this explanation node. </summary>
55 public virtual void SetDescription(System.String description)
57 this.description = description;
60 /// <summary>The sub-nodes of this explanation node. </summary>
61 public virtual Explanation[] GetDetails()
63 if (details == null)
64 return null;
65 return (Explanation[]) details.ToArray(typeof(Explanation));
68 /// <summary>Adds a sub-node to this explanation node. </summary>
69 public virtual void AddDetail(Explanation detail)
71 if (details == null)
72 details = new System.Collections.ArrayList();
73 details.Add(detail);
76 /// <summary>Render an explanation as text. </summary>
77 public override System.String ToString()
79 return ToString(0);
81 private System.String ToString(int depth)
83 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
84 for (int i = 0; i < depth; i++)
86 buffer.Append(" ");
88 buffer.Append(GetValue());
89 buffer.Append(" = ");
90 buffer.Append(GetDescription());
91 buffer.Append("\n");
93 Explanation[] details = GetDetails();
94 if (details != null)
96 for (int i = 0; i < details.Length; i++)
98 buffer.Append(details[i].ToString(depth + 1));
102 return buffer.ToString();
106 /// <summary>Render an explanation as HTML. </summary>
107 public virtual System.String ToHtml()
109 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
110 buffer.Append("<ul>\n");
112 buffer.Append("<li>");
113 buffer.Append(GetValue());
114 buffer.Append(" = ");
115 buffer.Append(GetDescription());
116 buffer.Append("</li>\n");
118 Explanation[] details = GetDetails();
119 if (details != null)
121 for (int i = 0; i < details.Length; i++)
123 buffer.Append(details[i].ToHtml());
127 buffer.Append("</ul>\n");
129 return buffer.ToString();