1 2 3 4 package net.nutch.searcher; 5 6 import java.io.DataInput ; 7 import java.io.DataOutput ; 8 import java.io.IOException ; 9 10 import net.nutch.io.Writable; 11 12 import java.util.logging.Logger ; 13 import net.nutch.util.LogFormatter; 14 15 16 public final class Hits implements Writable { 17 private static final Logger LOG = 18 LogFormatter.getLogger("net.nutch.searcher.Hits"); 19 20 private long total; 21 private boolean totalIsExact = true; 22 private Hit[] top; 23 24 public Hits() {} 25 26 public Hits(long total, Hit[] top) { 27 this.total = total; 28 this.top = top; 29 } 30 31 33 public long getTotal() { return total; } 34 35 37 public boolean totalIsExact() { return totalIsExact; } 38 39 40 public void setTotalIsExact(boolean isExact) { totalIsExact = isExact; } 41 42 43 public int getLength() { return top.length; } 44 45 46 public Hit getHit(int i) { return top[i]; } 47 48 49 public Hit[] getHits(int start, int length) { 50 Hit[] results = new Hit[length]; 51 for (int i = 0; i < length; i++) { 52 results[i] = top[start+i]; 53 } 54 return results; 55 } 56 57 58 public void write(DataOutput out) throws IOException { 59 out.writeLong(total); 60 out.writeInt(top.length); 61 for (int i = 0; i < top.length; i++) { 62 top[i].write(out); 63 } 64 } 65 66 public void readFields(DataInput in) throws IOException { 67 total = in.readLong(); 68 top = new Hit[in.readInt()]; 69 for (int i = 0; i < top.length; i++) { 70 top[i] = new Hit(); 71 top[i].readFields(in); 72 } 73 } 74 75 } 76 | Popular Tags |