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 import net.nutch.io.UTF8; 12 13 import java.util.logging.Logger ; 14 import net.nutch.util.LogFormatter; 15 16 17 public class Hit implements Writable, Comparable { 18 private static final Logger LOG = 19 LogFormatter.getLogger("net.nutch.searcher.Hit"); 20 21 private int indexNo; private int indexDocNo; private float score; private String site; private boolean moreFromSiteExcluded; 26 27 public Hit() {} 28 29 public Hit(int indexNo, int indexDocNo, float score, String site) { 30 this(indexDocNo, score, site); 31 this.indexNo = indexNo; 32 } 33 public Hit(int indexDocNo, float score, String site) { 34 this.indexDocNo = indexDocNo; 35 this.score = score; 36 if (site == null) 40 site = ""; 41 this.site = site; 42 } 43 44 45 public int getIndexNo() { return indexNo; } 46 public void setIndexNo(int indexNo) { this.indexNo = indexNo; } 47 48 49 public int getIndexDocNo() { return indexDocNo; } 50 51 52 public float getScore() { return score; } 53 54 55 public String getSite() { return site; } 56 57 59 public boolean moreFromSiteExcluded() { return moreFromSiteExcluded; } 60 61 63 public void setMoreFromSiteExcluded(boolean more){moreFromSiteExcluded=more;} 64 65 public void write(DataOutput out) throws IOException { 66 out.writeInt(indexDocNo); 67 out.writeFloat(score); 68 UTF8.writeString(out, site); 69 } 70 71 public void readFields(DataInput in) throws IOException { 72 indexDocNo = in.readInt(); 73 score = in.readFloat(); 74 site = UTF8.readString(in); 75 } 76 77 78 public String toString() { 79 return "#" + indexDocNo; 80 } 81 82 public boolean equals(Object o) { 83 if (!(o instanceof Hit)) 84 return false; 85 Hit other = (Hit)o; 86 return this.indexNo == other.indexNo 87 && this.indexDocNo == other.indexDocNo; 88 } 89 90 public int hashCode() { 91 return indexNo ^ indexDocNo; 92 } 93 94 public int compareTo(Object o) { 95 Hit other = (Hit)o; 96 if (other.score > this.score) { return 1; 98 } else if (other.score < this.score) { 99 return -1; 100 } else if (other.indexNo != this.indexNo) { 101 return other.indexNo - this.indexNo; } else { 103 return other.indexDocNo - this.indexDocNo; } 105 } 106 } 107 | Popular Tags |