1 16 17 package org.apache.lucene.search; 18 19 import java.io.IOException ; 20 21 import org.apache.lucene.document.Document; 22 23 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 43 Hit(Hits hits, int hitNumber) { 44 this.hits = hits; 45 this.hitNumber = hitNumber; 46 } 47 48 53 public Document getDocument() throws IOException { 54 if (!resolved) fetchTheHit(); 55 return doc; 56 } 57 58 63 public float getScore() throws IOException { 64 return hits.score(hitNumber); 65 } 66 67 72 public int getId() throws IOException { 73 return hits.id(hitNumber); 74 } 75 76 private void fetchTheHit() throws IOException { 77 doc = hits.doc(hitNumber); 78 resolved = true; 79 } 80 81 83 88 public float getBoost() throws IOException { 89 return getDocument().getBoost(); 90 } 91 92 100 public String get(String name) throws IOException { 101 return getDocument().get(name); 102 } 103 104 107 public String toString() { 108 StringBuffer buffer = new StringBuffer (); 109 buffer.append("Hit<"); 110 buffer.append(hits.toString()); 111 buffer.append(" ["); 112 buffer.append(hitNumber); 113 buffer.append("] "); 114 if (resolved) { 115 buffer.append("resolved"); 116 } else { 117 buffer.append("unresolved"); 118 } 119 buffer.append(">"); 120 return buffer.toString(); 121 } 122 123 124 } 125 | Popular Tags |