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);
}