3 using System
.Collections
;
6 namespace Lucene
.Net
.Search
8 /* ====================================================================
9 * The Apache Software License, Version 1.1
11 * Copyright (c) 2003 The Apache Software Foundation. All rights
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in
23 * the documentation and/or other materials provided with the
26 * 3. The end-user documentation included with the redistribution,
27 * if any, must include the following acknowledgment:
28 * "This product includes software developed by the
29 * Apache Software Foundation (http://www.apache.org/)."
30 * Alternately, this acknowledgment may appear in the software itself,
31 * if and wherever such third-party acknowledgments normally appear.
33 * 4. The names "Apache" and "Apache Software Foundation" and
34 * "Apache Lucene" must not be used to endorse or promote products
35 * derived from this software without prior written permission. For
36 * written permission, please contact apache@apache.org.
38 * 5. Products derived from this software may not be called "Apache",
39 * "Apache Lucene", nor may "Apache" appear in their name, without
40 * prior written permission of the Apache Software Foundation.
42 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
43 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
46 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
50 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
51 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
52 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * ====================================================================
56 * This software consists of voluntary contributions made by many
57 * individuals on behalf of the Apache Software Foundation. For more
58 * information on the Apache Software Foundation, please see
59 * <http://www.apache.org/>.
63 /// Expert: Describes the score computation for document and query.
66 public class Explanation
68 private float value; // the value of this node
69 private String description
; // what it represents
70 private ArrayList details
; // sub-explanations
72 public Explanation() {}
74 public Explanation(float value, String description
)
77 this.description
= description
;
81 /// The value assigned to this explanation node.
83 /// <returns></returns>
84 public float GetValue() { return value; }
87 /// Sets the value assigned to this explanation node.
89 /// <param name="value"></param>
90 public void SetValue(float value) { this.value = value; }
93 /// A description of this explanation node.
95 /// <returns></returns>
96 public String
GetDescription() { return description; }
99 /// Sets the description of this explanation node.
101 /// <param name="description"></param>
102 public void SetDescription(String description
)
104 this.description
= description
;
108 /// The sub-nodes of this explanation node.
110 /// <returns></returns>
111 public Explanation
[] GetDetails()
115 return (Explanation
[])details
.ToArray(typeof(Explanation
));
119 /// The sub-nodes of this explanation node.
121 /// <param name="detail"></param>
122 public void AddDetail(Explanation detail
)
125 details
= new ArrayList();
130 /// Render an explanation as HTML.
132 /// <returns></returns>
133 public override String
ToString()
138 private String
ToString(int depth
)
140 StringBuilder buffer
= new StringBuilder();
141 for (int i
= 0; i
< depth
; i
++)
145 buffer
.Append(Number
.ToString(GetValue()));
146 buffer
.Append(" = ");
147 buffer
.Append(GetDescription());
150 Explanation
[] details
= GetDetails();
153 for (int i
= 0 ; i
< details
.Length
; i
++)
155 buffer
.Append(details
[i
].ToString(depth
+1));
159 return buffer
.ToString();
163 /// Render an explanation as HTML.
165 /// <returns></returns>
166 public String
ToHtml()
168 StringBuilder buffer
= new StringBuilder();
169 buffer
.Append("<ul>\n");
171 buffer
.Append("<li>");
172 buffer
.Append(Number
.ToString(GetValue()));
173 buffer
.Append(" = ");
174 buffer
.Append(GetDescription());
175 buffer
.Append("</li>\n");
177 Explanation
[] details
= GetDetails();
180 for (int i
= 0 ; i
< details
.Length
; i
++)
182 buffer
.Append(details
[i
].ToHtml());
186 buffer
.Append("</ul>\n");
188 return buffer
.ToString();