QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / beagled / Lucene.Net / Search / Hit.cs
blobea74018149bf9cb4a9577720ef2de9a030f91bb0
1 /*
2 * Copyright 2005 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.
17 using System;
18 using Document = Lucene.Net.Documents.Document;
20 namespace Lucene.Net.Search
23 /// <summary> Wrapper used by {@link HitIterator} to provide a lazily loaded hit
24 /// from {@link Hits}.
25 ///
26 /// </summary>
27 /// <author> Jeremy Rayner
28 /// </author>
29 [Serializable]
30 public class Hit
33 private Document doc = null;
35 private bool resolved = false;
37 private Hits hits = null;
38 private int hitNumber;
40 /// <summary> Constructed from {@link HitIterator}</summary>
41 /// <param name="hits">Hits returned from a search
42 /// </param>
43 /// <param name="hitNumber">Hit index in Hits
44 /// </param>
45 internal Hit(Hits hits, int hitNumber)
47 this.hits = hits;
48 this.hitNumber = hitNumber;
51 /// <summary> Returns document for this hit.
52 ///
53 /// </summary>
54 /// <seealso cref="Hits.Doc(int)">
55 /// </seealso>
56 public virtual Document GetDocument()
58 if (!resolved)
59 FetchTheHit();
60 return doc;
63 /// <summary> Returns score for this hit.
64 ///
65 /// </summary>
66 /// <seealso cref="Hits.Score(int)">
67 /// </seealso>
68 public virtual float GetScore()
70 return hits.Score(hitNumber);
73 /// <summary> Returns id for this hit.
74 ///
75 /// </summary>
76 /// <seealso cref="Hits.Id(int)">
77 /// </seealso>
78 public virtual int GetId()
80 return hits.Id(hitNumber);
83 private void FetchTheHit()
85 doc = hits.Doc(hitNumber);
86 resolved = true;
89 // provide some of the Document style interface (the simple stuff)
91 /// <summary> Returns the boost factor for this hit on any field of the underlying document.
92 ///
93 /// </summary>
94 /// <seealso cref="Document.GetBoost()">
95 /// </seealso>
96 public virtual float GetBoost()
98 return GetDocument().GetBoost();
101 /// <summary> Returns the string value of the field with the given name if any exist in
102 /// this document, or null. If multiple fields exist with this name, this
103 /// method returns the first value added. If only binary fields with this name
104 /// exist, returns null.
105 ///
106 /// </summary>
107 /// <seealso cref="Document.Get(String)">
108 /// </seealso>
109 public virtual System.String Get(System.String name)
111 return GetDocument().Get(name);
114 /// <summary> Prints the parameters to be used to discover the promised result.</summary>
115 public override System.String ToString()
117 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
118 buffer.Append("Hit<");
119 buffer.Append(hits.ToString());
120 buffer.Append(" [");
121 buffer.Append(hitNumber);
122 buffer.Append("] ");
123 if (resolved)
125 buffer.Append("resolved");
127 else
129 buffer.Append("unresolved");
131 buffer.Append(">");
132 return buffer.ToString();