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.
17 namespace Lucene
.Net
.Search
20 /// <summary>Expert: Describes the score computation for document and query. </summary>
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
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()
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()
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()
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
)
72 details
= new System
.Collections
.ArrayList();
76 /// <summary>Render an explanation as text. </summary>
77 public override System
.String
ToString()
81 private System
.String
ToString(int depth
)
83 System
.Text
.StringBuilder buffer
= new System
.Text
.StringBuilder();
84 for (int i
= 0; i
< depth
; i
++)
88 buffer
.Append(GetValue());
90 buffer
.Append(GetDescription());
93 Explanation
[] details
= GetDetails();
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();
121 for (int i
= 0; i
< details
.Length
; i
++)
123 buffer
.Append(details
[i
].ToHtml());
127 buffer
.Append("</ul>\n");
129 return buffer
.ToString();