2 * Copyright 2005 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.
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}.
27 /// <author> Jeremy Rayner
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
43 /// <param name="hitNumber">Hit index in Hits
45 internal Hit(Hits hits
, int hitNumber
)
48 this.hitNumber
= hitNumber
;
51 /// <summary> Returns document for this hit.
54 /// <seealso cref="Hits.Doc(int)">
56 public virtual Document
GetDocument()
63 /// <summary> Returns score for this hit.
66 /// <seealso cref="Hits.Score(int)">
68 public virtual float GetScore()
70 return hits
.Score(hitNumber
);
73 /// <summary> Returns id for this hit.
76 /// <seealso cref="Hits.Id(int)">
78 public virtual int GetId()
80 return hits
.Id(hitNumber
);
83 private void FetchTheHit()
85 doc
= hits
.Doc(hitNumber
);
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.
94 /// <seealso cref="Document.GetBoost()">
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.
107 /// <seealso cref="Document.Get(String)">
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());
121 buffer
.Append(hitNumber
);
125 buffer
.Append("resolved");
129 buffer
.Append("unresolved");
132 return buffer
.ToString();