Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Explanation.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Collections.Generic;
20 
21 namespace Lucene.Net.Search
22 {
23 
25  [Serializable]
26  public class Explanation
27  {
28  private float value; // the value of this node
29  private System.String description; // what it represents
30  private List<Explanation> details; // sub-explanations
31 
32  public Explanation()
33  {
34  }
35 
36  public Explanation(float value, System.String description)
37  {
38  this.value = value;
39  this.description = description;
40  }
41 
50  public virtual bool IsMatch
51  {
52  get { return (0.0f < Value); }
53  }
54 
55 
57  public virtual float Value
58  {
59  get { return value; }
60  set { this.value = value; }
61  }
62 
64  public virtual string Description
65  {
66  get { return description; }
67  set { this.description = value; }
68  }
69 
73  protected internal virtual string Summary
74  {
75  get { return Value + " = " + Description; }
76  }
77 
79  public virtual Explanation[] GetDetails()
80  {
81  if (details == null)
82  return null;
83  return details.ToArray();
84  }
85 
87  public virtual void AddDetail(Explanation detail)
88  {
89  if (details == null)
90  details = new List<Explanation>();
91  details.Add(detail);
92  }
93 
95  public override System.String ToString()
96  {
97  return ToString(0);
98  }
99 
100  protected internal virtual System.String ToString(int depth)
101  {
102  System.Text.StringBuilder buffer = new System.Text.StringBuilder();
103  for (int i = 0; i < depth; i++)
104  {
105  buffer.Append(" ");
106  }
107  buffer.Append(Summary);
108  buffer.Append("\n");
109 
110  Explanation[] details = GetDetails();
111  if (details != null)
112  {
113  for (int i = 0; i < details.Length; i++)
114  {
115  buffer.Append(details[i].ToString(depth + 1));
116  }
117  }
118 
119  return buffer.ToString();
120  }
121 
123  public virtual System.String ToHtml()
124  {
125  System.Text.StringBuilder buffer = new System.Text.StringBuilder();
126  buffer.Append("<list>\n");
127 
128  buffer.Append("<item>");
129  buffer.Append(Summary);
130  buffer.Append("<br />\n");
131 
132  Explanation[] details = GetDetails();
133  if (details != null)
134  {
135  for (int i = 0; i < details.Length; i++)
136  {
137  buffer.Append(details[i].ToHtml());
138  }
139  }
140 
141  buffer.Append("</item>\n");
142  buffer.Append("</list>\n");
143 
144  return buffer.ToString();
145  }
146 
154  [Serializable]
155  public abstract class IDFExplanation
156  {
158  public abstract float Idf { get; }
159 
165  public abstract System.String Explain();
166  }
167  }
168 }