gpt4 book ai didi

java - lucene index getDocCount() 返回的值与总输入文档数不同

转载 作者:行者123 更新时间:2023-11-30 11:05:06 25 4
gpt4 key购买 nike

我有 1.2M 行要索引,每行在 lucene 索引编写器中被读取为一个文档。建立索引后,我尝试断言已索引的记录总数。这个数字小于 1.2M。

添加文件的方法如下:

    Directory fsDir = FSDirectory.open(this.indexLoc, NoLockFactory.INSTANCE);
IndexWriterConfig iwConf = new IndexWriterConfig(analyzer);
iwConf.setOpenMode(mode);
IndexWriter indexWriter = new IndexWriter(fsDir, iwConf);
int count=0;
FileInputStream input;
input = new FileInputStream(new File(String.valueOf(dir)));
CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
decoder.onMalformedInput(CodingErrorAction.IGNORE);
InputStreamReader isr = new InputStreamReader(input,decoder);
BufferedReader reader = new BufferedReader(isr);
StringBuilder content = new StringBuilder();
String line;

while ((line = reader.readLine()) != null) {
Document d = new Document();
d.add(new TextField(this.fieldName, line, Store.NO));
indexWriter.addDocument(d);
count++;
}

indexWriter.commit();
indexWriter.close();
reader.close();
isr.close();
input.close();
}

我获取索引文档编号的方式如下:

IndexReader reader = DirectoryReader.open(FSDirectory.open(this.indexLoc));
int docNum = reader.getDocCount(this.fieldName);

我查到1.2M已经添加到文件d中了。但是,为什么变量docNum的值小于1.2M呢?

当我用小尺寸文档测试时,比如 1k,这两个数字是一致的。

另外,我使用的是 lucene 5.0。

最佳答案

IndexReader.getDocCount(String field) 将返回对该字段具有至少一个术语 的文档数。因此,如果 line 为空,则文档计数不会增加 addDocument

关于java - lucene index getDocCount() 返回的值与总输入文档数不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com