在Lucene中,为什么我的增强文档和未增强文档的得分相同? [英] In Lucene, why do my boosted and unboosted documents get the same score?
问题描述
在索引时,我以这种方式增强某些文档:
At index time I am boosting certain document in this way:
if (myCondition)
{
document.SetBoost(1.2f);
}
但是在搜索时,具有完全相同质量的文档,但是某些通过和某些失败的myCondition最终都具有相同的分数.
But at search time documents with all the exact same qualities but some passing and some failing myCondition all end up having the same score.
这是搜索代码:
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.Add(new TermQuery(new Term(FieldNames.HAS_PHOTO, "y")), BooleanClause.Occur.MUST);
booleanQuery.Add(new TermQuery(new Term(FieldNames.AUTHOR_TYPE, AuthorTypes.BLOGGER)), BooleanClause.Occur.MUST_NOT);
indexSearcher.Search(booleanQuery, 10);
您能告诉我我该怎么做才能获得被提高的文档以获得更高的分数?
Can you tell me what I need to do to get the documents that were boosted to get a higher score?
非常感谢!
推荐答案
Lucene使用SmallFloat#floatToByte315方法对单个字节上的增强编码(尽管通常将浮点数编码为四个字节).因此,将字节转换回浮点数时,精度可能会大大降低.
Lucene encodes boosts on a single byte (although a float is generally encoded on four bytes) using the SmallFloat#floatToByte315 method. As a consequence, there can be a big loss in precision when converting back the byte to a float.
在您的情况下,SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.2f))
返回1f,因为1f和1.2f彼此距离太近.尝试使用更大的提升,以使您的文档获得不同的分数. (例如1.25,SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.25f))
给出1.25f.)
In your case SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.2f))
returns 1f because 1f and 1.2f are too close to each other. Try using a bigger boost so that your documents get different scores. (For exemple 1.25, SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.25f))
gives 1.25f.)
这篇关于在Lucene中,为什么我的增强文档和未增强文档的得分相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!