Lucene.净持久提升值

本文关键字:Lucene | 更新日期: 2023-09-27 18:11:43

我创建了一个索引,但它有很多垃圾数据。我希望实现的是一个投票系统,在这个系统中,更多的投票等于更高的提升值。不幸的是,在用户提交投票后,提升值不会保存回索引。

这是我的Boost函数的代码分解,有人对我做错了什么有任何想法吗?我使用了explain(),但它与boost值没有任何关系。

BoostUp(int documentId)
{

    IndexSearcher searcher = new IndexSearcher(dir);
    Document oldDoc = search.doc(documentId);
    //get all the stored information from old document
    Document updatedDocument = new Document();
    //Add fields containing data from old document.
    updatedDocument.Boost = oldDoc.Boost * 1.5F;
    IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_30), false, MaxFieldLength.LIMITED);
    Term uniqueTerm = new term("content_id", content_id_from_old_document);
    writer.UpdateDocument(uniqueTerm, updatedDocument);
    writer.Commit();
    writer.Dispose();
}

Lucene.净持久提升值

问题是您无法从索引中检索该值。检索到的文档没有增强集。它与其他索引时间评分因素相结合,并在索引中编码,因此无法检索它。

我认为,解决方案是将boost保存为存储在索引中的字段,并检索该字段,并使用它来修改和设置boost。

下面的内容:

Field boostField = oldDoc.getField("saved_boost");
float newBoost = boostField.numericValue().floatValue() * 1.5F;
updatedDocument.setBoost(newBoost);
updatedDocument.removeField("saved_boost");
NumericField boostField = new NumericField("saved_boost",Field.Store.YES,false);
boostField.setFloatValue(newBoost);
updatedDocument.add(boostField);
//No changes from here on...
IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_30), false, MaxFieldLength.LIMITED);
Term uniqueTerm = new term("content_id", content_id_from_old_document);
writer.UpdateDocument(uniqueTerm, updatedDocument);