简体   繁体   English

Lucene docID可靠性

[英]Lucene docID reliability

Hi 你好
If only insert operation occur on lucene index (no delete/update), is it true that docID is not changing ? 如果只对lucene索引进行插入操作(没有删除/更新),那么docID是否正在改变? and its also reliable 而且它也很可靠
if it is true, i want to use it as loading FieldCache incrementally to lower down the overhead of loading all documents, what is the best solution for that ?? 如果是真的,我想用它来逐步加载FieldCache来降低加载所有文件的开销,那么最好的解决方案是什么?

I'm not quite sure what you're planning to do with the field cache, but my understanding of document ids is that they can change during an insert, depending on pending deletes, merge policies etc. 我不太确定你打算用字段缓存做什么,但我对文档ID的理解是它们可以在插入期间更改,具体取决于待处理的删除,合并策略等。

ie Document ID should not be used past a commit boundary on a reopened index reader 即,在重新打开的索引读取器上不应使用文档ID超过提交边界

Hope this helps, 希望这可以帮助,

The document id is static within a segment. 文档ID在段内是静态的。 IndexReader.Open (usually) opens a DirectoryReader which combines several SegmentReader . IndexReader.Open (通常)打开一个DirectoryReader ,它结合了几个SegmentReader You'll need to pass the "bottom" reader to the FieldCache for the population to work correctly. 您需要将“底部”阅读器传递给FieldCache才能使群体正常工作。

Here's an example from FieldCache with frequently updating index which ensures that only the newly read segment is read by the FieldCache, instead of the topmost reader (which will considered changed at every commit). 以下是FieldCache中的一个示例, 它经常更新索引 ,确保FieldCache只读取新读取的段,而不是最顶层的读取器(在每次提交时都会被更改)。

var directory = FSDirectory.Open(new DirectoryInfo("index"));
var reader = IndexReader.Open(directory, readOnly: true);
var documentId = 1337;

// Grab all subreaders.
var subReaders = new List<IndexReader>();
ReaderUtil.GatherSubReaders(subReaders, reader);

// Loop through all subreaders. While subReaderId is higher than the
// maximum document id in the subreader, go to next.
var subReaderId = documentId;
var subReader = subReaders.First(sub => {
    if (sub.MaxDoc() < subReaderId) {
        subReaderId -= sub.MaxDoc();
        return false;
    }

    return true;
});

var values = FieldCache_Fields.DEFAULT.GetInts(subReader, "newsdate");
var value = values[subReaderId];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM