📄 hit.java
字号:
/* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
/* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
package net.nutch.searcher;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import net.nutch.io.Writable;
import net.nutch.io.UTF8;
import java.util.logging.Logger;
import net.nutch.util.LogFormatter;
/** A document which matched a query in an index. */
public class Hit implements Writable, Comparable {
private static final Logger LOG =
LogFormatter.getLogger("net.nutch.searcher.Hit");
private int indexNo; // index id
private int indexDocNo; // index-relative id
private float score; // its score for the query
private String site; // its website name
private String mode;
/**
* Add by xie shuqiang
* for sort time
*/
private int sortInt;
private int clustNo;
private int grpNo;
private int grpDocs;
private float siteRank;
private float siteRankSum = 0.0f;
private boolean moreFromSiteExcluded;
public Hit() {}
/**
* Add by xie shuqiang
* @param indexDocNo
* @param sortInt
* @param site
*/
public Hit(int indexDocNo, float score, int grpNo, int grpDocs,int sortInt, String site){
this.indexDocNo = indexDocNo;
this.score = score;
this.sortInt = sortInt;
if (site == null)
site = "";
this.site = site;
this.grpDocs = grpDocs;
this.grpNo = grpNo;
}
public Hit(int index, int indexDocNo, float score, String site){
this(index, indexDocNo, score, 0, 0, site);
}
public Hit(int indexDocNo, float score, String site){
this( indexDocNo, score, 0, 0, site);
}
public Hit(int indexDocNo, float score, int grpNo, int grpDocs){
this(indexDocNo,score,grpNo,grpDocs,null);
}
public Hit(int indexDocNo, float score, int grpNo, int grpDocs, int sortInt){
this(indexDocNo,score,grpNo, grpDocs, sortInt,null);
}
public Hit(int indexNo,int indexDocNo,float score, int grpNo, int grpDocs, int sortInt){
this(indexNo,indexDocNo,score,grpNo,grpDocs,sortInt,null);
}
public Hit(int indexNo, int indexDocNo, float score, int grpNo, int grpDocs,int sortInt, String site) {
this(indexDocNo, score, grpNo,grpDocs,sortInt, site);
this.indexNo = indexNo;
}
public Hit(int indexNo, int indexDocNo, float score, int grpNo, int grpDocs,int sortInt, String site,int clustNo) {
this(indexDocNo, score, grpNo,grpDocs,sortInt, site);
this.indexNo = indexNo;
this.clustNo = clustNo;
}
public Hit(int indexNo, int indexDocNo, float score, int grpNo, int grpDocs, String site) {
this(indexDocNo, score, grpNo, grpDocs, site);
this.indexNo = indexNo;
this.sortInt = 0;
}
public Hit(int indexNo, int indexDocNo, float score, int grpNo, int grpDocs, String site,int clustNo) {
this(indexDocNo, score, grpNo, grpDocs, site);
this.indexNo = indexNo;
this.clustNo = clustNo;
this.sortInt = 0;
}
public Hit(int indexDocNo, float score, int grpNo, int grpDocs, String site) {
this.indexDocNo = indexDocNo;
this.score = score;
// 20041006, xing
// The following fixes a bug that causes cached.jsp, text.jsp, etc.,
// to fail in distributed search. "Release 0.6, note 14" in CHANGES.txt
if (site == null)
site = "";
this.site = site;
this.sortInt = 0;
this.grpNo = grpNo;
this.grpDocs = grpDocs;
}
/** Return the index number that this hit came from. */
public int getIndexNo() { return indexNo; }
public void setIndexNo(int indexNo) { this.indexNo = indexNo; }
/** Return the document number of this hit within an index. */
public int getIndexDocNo() { return indexDocNo; }
/** Return the degree to which this document matched the query. */
public float getScore() { return score; }
/**
* Add by xie shuqiang
* @return
*/
public int getSortInt(){ return sortInt; }
public int getClustNo(){ return clustNo; }
public int getGrpNo(){ return grpNo ;};
public int getGrpDocs(){ return grpDocs; };
public void setGrpDocs( int docs ){ this.grpDocs = docs; };
/** Return the name of this this document's website. */
public String getSite() { return site; }
/** True iff other, lower-scoring, hits from the same site have been excluded
* from the list which contains this hit.. */
public boolean moreFromSiteExcluded() { return moreFromSiteExcluded; }
/** True iff other, lower-scoring, hits from the same site have been excluded
* from the list which contains this hit.. */
public void setMoreFromSiteExcluded(boolean more){moreFromSiteExcluded=more;}
public void write(DataOutput out) throws IOException {
out.writeInt(indexDocNo);
out.writeFloat(score);
out.writeInt(sortInt);
out.writeInt(grpNo);
out.writeInt(grpDocs);
out.writeInt(clustNo);
out.writeFloat(siteRank);
out.writeFloat(siteRankSum);
UTF8.writeString(out, site);
}
public void readFields(DataInput in) throws IOException {
indexDocNo = in.readInt();
score = in.readFloat();
sortInt = in.readInt();
grpNo = in.readInt();
grpDocs = in.readInt();
clustNo = in.readInt();
siteRank = in.readFloat();
siteRankSum = in.readFloat();
site = UTF8.readString(in);
}
/** Display as a string. */
public String toString() {
return "#" + indexDocNo;
}
public boolean equals(Object o) {
if (!(o instanceof Hit))
return false;
Hit other = (Hit)o;
return this.indexNo == other.indexNo
&& this.indexDocNo == other.indexDocNo;
}
public int hashCode() {
return indexNo ^ indexDocNo;
}
public int compareTo(Object o) {
Hit other = (Hit)o;
if (other.sortInt > this.sortInt) {
return 1;
}else if (other.sortInt < this.sortInt) {
return -1;
}else if (other.score > this.score) { // prefer higher scores
return 1;
} else if (other.score < this.score) {
return -1;
} else if (other.indexNo != this.indexNo) {
return other.indexNo - this.indexNo; // prefer later indexes
} else {
return other.indexDocNo - this.indexDocNo; // prefer later docs
}
}
public void setClustNo(int clustNo) {
this.clustNo = clustNo;
}
public void setSiteRank(float rank){
this.siteRank = rank;
if (this.siteRankSum == 0.0f)
this.siteRankSum = rank;
}
public float getSiteRank(){
return this.siteRank;
}
public void setSiteRankSum(float rank){
this.siteRankSum = rank;
}
public float getSiteRankSum(){
return siteRankSum;
}
public String getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -