在lucene-4.0-alpha的Hightlights中有这么一段:
Added support for per-document values (DocValues). DocValues can be used for custom scoring factors (accessible via Similarity), for pre-sorted Sort values, and more.它的主要作用是custom scoring factors。
其实第一眼看到这HightLight,想到的是这对比原来的Document级别的Boost有哪些不同。Document级别的Boost虽然不是一个custom scoring factor, 但它也可以用来影响整体score(在根据score进行排序的情况下)。
Document boost的特点:
default value is 1.0
This value will be multiplied intothe score of all hits on this document.
Values are multiplied into the value of Fieldable#getBoost() of
each field in this document. Thus, this method in effect sets a default boost for the fields of this document, 也就是说this value会被传递影响到field boost,如果field boost是1.0的话,也就相当于给所有field 设置了一个和document一样的boost。
作用norm的一部分,这个boost没有单独的一块地方来store它。只能和其它norm共存一室。
基于这些点,这个boost所起的作用是被固定的。
相对于4.0中的DocValues。4.0中docvalues
应该说4.0中的docvalues是伴随着4.0中similarity做成一个component后而出现的。
在4.0之前整体体系结构上是使用 its hard-wired classic vector space scoring model。
在4.0中,我们可以通过similarity的封装,在计算score时,按自己的需要来决定docvalues中的值来影响socre。
@Override
public ExactSimScorer exactSimScorer(SimWeight stats, AtomicReaderContext context) throws IOException {
final ExactSimScorer sub = sim.exactSimScorer(stats, context);
final Source values = context.reader().docValues(boostField).getSource();
return new ExactSimScorer() {
@Override
public float score(int doc, int freq) {
return (float) values.getFloat(doc) * sub.score(doc, freq);
}
public Explanation explain(int doc, Explanation freq) {
Explanation boostExplanation = new Explanation((float) values.getFloat(doc), "indexDocValue(" + boostField + ")");
Explanation simExplanation = sub.explain(doc, freq);
Explanation expl = new Explanation(boostExplanation.getValue() * simExplanation.getValue(), "product of:");
expl.addDetail(boostExplanation);
expl.addDetail(simExplanation);
return expl;
}
};
}
在这里是直接使用docvalues中的值乘以原先的score。当然我们也可以相加,or其它运算。
Read full article from DocValues的理解应用_daysmileface_新浪博客
No comments:
Post a Comment