Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart4.png 81% of files have more coverage
22   124   10   2.75
4   48   0.45   8
8     1.25  
1    
 
  Hit       Line # 29 22 10 38.2% 0.38235295
 
  (1)
 
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.
15    */
16   
17    package org.apache.lucene.search;
18   
19    import java.io.IOException;
20   
21    import org.apache.lucene.document.Document;
22   
23    /**
24    * Wrapper used by {@link HitIterator} to provide a lazily loaded hit
25    * from {@link Hits}.
26    *
27    * @author Jeremy Rayner
28    */
 
29    public class Hit implements java.io.Serializable {
30   
31    private Document doc = null;
32   
33    private boolean resolved = false;
34   
35    private Hits hits = null;
36    private int hitNumber;
37   
38    /**
39    * Constructed from {@link HitIterator}
40    * @param hits Hits returned from a search
41    * @param hitNumber Hit index in Hits
42    */
 
43  2 toggle Hit(Hits hits, int hitNumber) {
44  2 this.hits = hits;
45  2 this.hitNumber = hitNumber;
46    }
47   
48    /**
49    * Returns document for this hit.
50    *
51    * @see Hits#doc(int)
52    */
 
53  2 toggle public Document getDocument() throws IOException {
54  2 if (!resolved) fetchTheHit();
55  2 return doc;
56    }
57   
58    /**
59    * Returns score for this hit.
60    *
61    * @see Hits#score(int)
62    */
 
63  0 toggle public float getScore() throws IOException {
64  0 return hits.score(hitNumber);
65    }
66   
67    /**
68    * Returns id for this hit.
69    *
70    * @see Hits#id(int)
71    */
 
72  0 toggle public int getId() throws IOException {
73  0 return hits.id(hitNumber);
74    }
75   
 
76  2 toggle private void fetchTheHit() throws IOException {
77  2 doc = hits.doc(hitNumber);
78  2 resolved = true;
79    }
80   
81    // provide some of the Document style interface (the simple stuff)
82   
83    /**
84    * Returns the boost factor for this hit on any field of the underlying document.
85    *
86    * @see Document#getBoost()
87    */
 
88  0 toggle public float getBoost() throws IOException {
89  0 return getDocument().getBoost();
90    }
91   
92    /**
93    * Returns the string value of the field with the given name if any exist in
94    * this document, or null. If multiple fields exist with this name, this
95    * method returns the first value added. If only binary fields with this name
96    * exist, returns null.
97    *
98    * @see Document#get(String)
99    */
 
100  1 toggle public String get(String name) throws IOException {
101  1 return getDocument().get(name);
102    }
103   
104    /**
105    * Prints the parameters to be used to discover the promised result.
106    */
 
107  0 toggle public String toString() {
108  0 StringBuffer buffer = new StringBuffer();
109  0 buffer.append("Hit<");
110  0 buffer.append(hits.toString());
111  0 buffer.append(" [");
112  0 buffer.append(hitNumber);
113  0 buffer.append("] ");
114  0 if (resolved) {
115  0 buffer.append("resolved");
116    } else {
117  0 buffer.append("unresolved");
118    }
119  0 buffer.append(">");
120  0 return buffer.toString();
121    }
122   
123   
124    }