我创建了两个类,但我不知道如何处理我的函数的有效负载,它计算每个术语的分数。我不知道我是否必须创建作者类,请有人可以帮助我。 第一个问题是:
import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.util.BytesRef;
public class BoostingSimilarity extends DefaultSimilarity {
public float scorePayload(int docID, int start, int end, BytesRef payload) {
float pload = 1.0f;
if (payload != null) {
pload = PayloadHelper.decodeFloat(payload.bytes);
}
System.out.println("===> docid: " + docID + " payload: " + pload);
return pload;
}}
seconde classe是: 我添加了我的idflocal功能如下,但我不确定我做的是否正确:
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.TokenFilter;
import java.io.IOException;
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.util.BytesRef;
import static Package.FonctionIDFlocal.idflocal;
public class BulletinPayloadsFilter extends TokenFilter {
private PayloadAttribute attr;
BulletinPayloadsFilter(TokenStream in,float idflocal) {
super(in);
attr = addAttribute(PayloadAttribute.class);
}
public final boolean incrementToken() throws IOException {
if (input.incrementToken()) {
BytesRef p =new BytesRef(PayloadHelper.encodeFloat(idflocal));;
attr.setPayload(p);
} else {
attr.setPayload(null);
}
return false;
}
}
答案 0 :(得分:0)
你到底在想什么?它看起来像是一种自定义评分机制,它根据有效负载中的浮点值对文档进行评分。