在索引时,我以这种方式提升了某些文档:
if (myCondition)
{
document.SetBoost(1.2f);
}
但是在搜索时,所有质量完全相同的文档,除了一些通过和一些不及格的myCondition,最终都有相同的分数。
下面是搜索代码:
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);
你能告诉我我需要做什么才能得到提升的文档以获得更高的分数吗?
非常感谢!
发布于 2011-11-10 00:49:30
Lucene使用SmallFloat#floatToByte315方法对单字节上的boosts进行编码(尽管浮点数通常编码在四个字节上)。因此,在将字节转换回浮点数时,可能会有很大的精度损失。
在本例中,SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.2f))
返回1f,因为1f和1.2f太接近了。尝试使用更大的提升,以便您的文档获得不同的分数。(例如1.25,SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.25f))
给出了1.25f。)
发布于 2011-11-06 05:54:12
这是请求的测试程序,它太长了,无法在评论中发布。
class Program
{
static void Main(string[] args)
{
RAMDirectory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer());
const string FIELD = "name";
for (int i = 0; i < 10; i++)
{
StringBuilder notes = new StringBuilder();
notes.AppendLine("This is a note 123 - " + i);
string text = notes.ToString();
Document doc = new Document();
var field = new Field(FIELD, text, Field.Store.YES, Field.Index.NOT_ANALYZED);
if (i % 2 == 0)
{
field.SetBoost(1.5f);
doc.SetBoost(1.5f);
}
else
{
field.SetBoost(0.1f);
doc.SetBoost(0.1f);
}
doc.Add(field);
writer.AddDocument(doc);
}
writer.Commit();
//string TERM = QueryParser.Escape("*+*");
string TERM = "T";
IndexSearcher searcher = new IndexSearcher(dir);
Query query = new PrefixQuery(new Term(FIELD, TERM));
var hits = searcher.Search(query);
int count = hits.Length();
Console.WriteLine("Hits - {0}", count);
for (int i = 0; i < count; i++)
{
var doc = hits.Doc(i);
Console.WriteLine(doc.ToString());
var explain = searcher.Explain(query, i);
Console.WriteLine(explain.ToString());
}
}
}
https://stackoverflow.com/questions/7899031
复制相似问题