2 * Copyright 2004 The Apache Software Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 namespace Lucene
.Net
.Search
22 /// <summary>Expert: Describes the score computation for document and query. </summary>
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
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()
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()
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()
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
)
74 details
= new System
.Collections
.ArrayList();
78 /// <summary>Render an explanation as text. </summary>
79 public override System
.String
ToString()
83 private System
.String
ToString(int depth
)
85 System
.Text
.StringBuilder buffer
= new System
.Text
.StringBuilder();
86 for (int i
= 0; i
< depth
; i
++)
90 buffer
.Append(GetValue());
92 buffer
.Append(GetDescription());
95 Explanation
[] details
= GetDetails();
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();
123 for (int i
= 0; i
< details
.Length
; i
++)
125 buffer
.Append(details
[i
].ToHtml());
129 buffer
.Append("</ul>\n");
131 return buffer
.ToString();