lucene代码分析11

2021SC@SDUSC
按照基本索引链关闭存储域和词向量信息
代码为:
closeDocStore();
flushState.numDocsInStore = 0;
其主要是根据基本索引链结构,关闭存储域和词向量信息:

consumer(DocFieldProcessor).closeDocStore(flushState);

consumer(DocInverter).closeDocStore(state);
consumer(TermsHash).closeDocStore(state);

consumer(FreqProxTermsWriter).closeDocStore(state);

if (nextTermsHash != null) nextTermsHash.closeDocStore(state);

consumer(TermVectorsTermsWriter).closeDocStore(state);
endConsumer(NormsWriter).closeDocStore(state);

fieldsWriter(StoredFieldsWriter).closeDocStore(state);
其中有实质意义的是以下两个 closeDocStore:
词向量的关闭:TermVectorsTermsWriter.closeDocStore(SegmentWriteState)
void closeDocStore(final SegmentWriteState state) throws IOException {
if (tvx != null) {
//为不保存词向量的文档在 tvd 文件中写入零。即便不保存词向量,在 tvx, tvd 中也保留一个位置
fill(state.numDocsInStore - docWriter.getDocStoreOffset());
//关闭 tvx, tvf, tvd 文件的写入流
tvx.close();
tvf.close();
tvd.close();
tvx = null;
//记录写入的文件名,为以后生成 cfs 文件的时候,将这些写入的文件生成一个统一的
cfs 文件。
state.flushedFiles.add(state.docStoreSegmentName + “.” +
IndexFileNames.VECTORS_INDEX_EXTENSION);
state.flushedFiles.add(state.docStoreSegmentName + “.” +
IndexFileNames.VECTORS_FIELDS_EXTENSION);
state.flushedFiles.add(state.docStoreSegmentName + “.” +
IndexFileNames.VECTORS_DOCUMENTS_EXTENSION);
//从 DocumentsWriter 的成员变量 openFiles 中删除,未来可能被 IndexFileDeleter 删除
docWriter.removeOpenFile(state.docStoreSegmentName + “.” +
IndexFileNames.VECTORS_INDEX_EXTENSION);
docWriter.removeOpenFile(state.docStoreSegmentName + “.” +
IndexFileNames.VECTORS_FIELDS_EXTENSION);
docWriter.removeOpenFile(state.docStoreSegmentName + “.” +
IndexFileNames.VECTORS_DOCUMENTS_EXTENSION);
lastDocID = 0;
}
}
存储域的关闭:public void closeDocStore(SegmentWriteState state) throws IOException {
//关闭 fdx, fdt 写入流
fieldsWriter.close();
–> fieldsStream.close();
–> indexStream.close();
fieldsWriter = null;
lastDocID = 0;
//记录写入的文件名
state.flushedFiles.add(state.docStoreSegmentName + “.” +
IndexFileNames.FIELDS_EXTENSION);
state.flushedFiles.add(state.docStoreSegmentName + “.” +
IndexFileNames.FIELDS_INDEX_EXTENSION);
state.docWriter.removeOpenFile(state.docStoreSegmentName + “.” +
IndexFileNames.FIELDS_EXTENSION);
state.docWriter.removeOpenFile(state.docStoreSegmentName + “.” +
IndexFileNames.FIELDS_INDEX_EXTENSION);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值