【问题标题】:Lucene.Net persisting boost valuesLucene.Net 持续提升值
【发布时间】:2013-04-24 10:34:57
【问题描述】:

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

这是我的 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();
}

【问题讨论】:

    标签: c# search lucene.net lucene


    【解决方案1】:

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

    我认为解决方案是将 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);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-21
    • 2014-07-02
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    相关资源
    最近更新 更多