`
guming123416
  • 浏览: 18673 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Lucene(2.4.1)技术研究(5)--IndexWrite类源代码解析(二)--Directo

阅读更多

首先我们看构造函数中的第一个类Directory 类。根据这个类的英文,我们能得出这个类就是关于目录操作的。Directory 是一个抽象类。其有4个子类,分别是:DbDirectory, FSDirectory, JEDirectory, RAMDirectory

首先我们看看Directory 的类
public abstract class Directory {
volatile boolean isOpen = true;
/*** 持有一个LockFactory的实例(实现锁定这个目录实例)*/
protected LockFactory lockFactory;
/**返回该目录下的所有文件数组.如果这个目录下没有文件存在,或者存在权限问题不能访问,该方法可能返回Null*/
public abstract String[] list() throws IOException;
/** * 返回指定名称的文件是不是存在 */
public abstract boolean fileExists(String name)
throws IOException;
/**返回指定名称的文件最后修改的时间
public abstract long fileModified(String name) throws IOException;
/**设置指定文件名的文件最后的修改时间为当前时间*/
public abstract void touchFile(String name) throws IOException;

/**删除指定文件。 */
public abstract void deleteFile(String name)throws IOException;
/**返回指定文件的长度。 */
public abstract long fileLength(String name) throws IOException;
/** 在当前目录下使用给定的名称创建一个空的文件。并且返回一个流来写该文件。*/
public abstract IndexOutput createOutput(String name) throws IOException;
/** * Lucene使用该方法确保所有的针对该文件的写操作都会存储到Index。并且阻止machine/OS发生故障 破坏该index。*/
public void sync(String name) throws IOException {}
/**获取已经存在的一个文件的IndexInput流操作该文件。 */
public abstract IndexInput openInput(String name) throws IOException;
/** 返回已经存在的一个文件、并且使用指定大小的缓冲的IndexInput,但是当前目录也可能忽略该缓冲池的大小,
* 当前主要是考虑CompoundFileReader和FSDirectory对于次参数的需求。*/
public IndexInput openInput(String name, int bufferSize) throws IOException {
return openInput(name);
}
/** 创建一个指定名称的锁/
public Lock makeLock(String name) {
return lockFactory.makeLock(name);
}
/**
* 清除指定的锁定(强行解锁和删除)这不仅要求在这个时候当前的锁一定不在使用。 */
public void clearLock(String name) throws IOException {
if (lockFactory != null) {
lockFactory.clearLock(name);
}
}
/** 结束这个store. */
public abstract void close() throws IOException;

/**设置LockFactory,此目录实例应使其锁定执行。每个LockFactory实例只用于一个目录(即,不要共用一个实例在多个目录) */
public void setLockFactory(LockFactory lockFactory) {
this.lockFactory = lockFactory;
lockFactory.setLockPrefix(this.getLockID());
}

/** 获得LockFactory,此目录例实例使用其锁定执行。请注意,这可能是无效的目录执行,提供自己锁执行*/
public LockFactory getLockFactory() {
return this.lockFactory;
}
/**过去锁实例的唯一表示ID的字符串描述*/
public String getLockID() {
return this.toString();
}
/**// 拷贝源目录src下的文件,复制到目的目录dest下面,拷贝完成后关闭源目录src*/
public static void copy(Directory src, Directory dest, boolean closeDirSrc) throws IOException {
final String[] files = src.list();
if (files == null)
throw new IOException("cannot read directory " + src + ": list() returned null");
byte[] buf = new byte[BufferedIndexOutput.BUFFER_SIZE];
for (int i = 0; i < files.length; i++) {
IndexOutput os = null;
IndexInput is = null;
try {
// create file in dest directory
os = dest.createOutput(files[i]);
// read current file
is = src.openInput(files[i]);
// and copy to dest directory
long len = is.length();
long readCount = 0;
while (readCount < len) {
int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len ? (int)(len - readCount) : BufferedIndexOutput.BUFFER_SIZE;
is.readBytes(buf, 0, toRead);
os.writeBytes(buf, toRead);
readCount += toRead;
}
} finally {
// graceful cleanup
try {
if (os != null)
os.close();
} finally {
if (is != null)
is.close();
}
}
}
if(closeDirSrc)
src.close();
}

从Directory抽象类的定义,我们可以得到如下几点:
1、管理锁工厂及其锁实例;
2、管理Directory目录实例的基本属性,主要是通过文件名称进行管理;
3、管理与操作该目录相关的一些流对象;
4、管理索引文件的拷贝。

分享到:
评论

相关推荐

    MMAnalyzer 分词必导入jar包(lucene-core-2.4.1.jar je-analysis-1.5.3.jar)

    然而,使用MMAnalyzer时,仅引入`jeasy.analysis.MMAnalyzer`的JAR包是不够的,因为这个类依赖于Lucene库,特别是`lucene-core-2.4.1.jar`。Lucene是一个高性能、全功能的全文搜索引擎库,它提供了一套完整的搜索...

    MMAnalyzer 分词jar包(lucene-core-2.4.1.jar je-analysis-1.5.3.jar)

    "lucene-core-2.4.1.jar"是Lucene的核心库,包含了Lucene的基本功能,如索引构建、查询解析、搜索等功能。虽然2.4.1版本相对较老,但在当时,它已经相当成熟,能够支持各种复杂的文本处理任务。这个库是MMAnalyzer...

    je-analysis-1.5.3、lucene-core-2.4.1分词组件

    本文将深入探讨"je-analysis-1.5.3"和"lucene-core-2.4.1"这两个分词组件,以及它们在相关场景中的应用。 首先,让我们了解什么是分词。分词,即词语切分,是自然语言处理(NLP)中的基本任务之一,它的目标是将...

    lucene-analyzers-smartcn-7.7.0-API文档-中文版.zip

    赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-analyzers-smartcn-7.7.0.pom; 包含翻译后的API文档:lucene-analyzers-smartcn-7.7.0-javadoc-API文档-中文(简体)版....

    lucene-analyzers-common-6.6.0-API文档-中文版.zip

    赠送源代码:lucene-analyzers-common-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-analyzers-common-6.6.0.pom; 包含翻译后的API文档:lucene-analyzers-common-6.6.0-javadoc-API文档-中文(简体)版.zip;...

    lucene-core-7.7.0-API文档-中文版.zip

    赠送源代码:lucene-core-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.7.0.pom; 包含翻译后的API文档:lucene-core-7.7.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.lucene:lucene...

    lucene-backward-codecs-7.3.1-API文档-中英对照版.zip

    赠送源代码:lucene-backward-codecs-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-backward-codecs-7.3.1.pom; 包含翻译后的API文档:lucene-backward-codecs-7.3.1-javadoc-API文档-中文(简体)-英语-对照...

    lucene-spatial-extras-7.3.1-API文档-中英对照版.zip

    赠送源代码:lucene-spatial-extras-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras-7.3.1.pom; 包含翻译后的API文档:lucene-spatial-extras-7.3.1-javadoc-API文档-中文(简体)-英语-对照版....

    lucene-analyzers-smartcn-7.7.0-API文档-中英对照版.zip

    赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-analyzers-smartcn-7.7.0.pom; 包含翻译后的API文档:lucene-analyzers-smartcn-7.7.0-javadoc-API文档-中文(简体)-英语...

    lucene-spatial-extras-7.2.1-API文档-中英对照版.zip

    赠送源代码:lucene-spatial-extras-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras-7.2.1.pom; 包含翻译后的API文档:lucene-spatial-extras-7.2.1-javadoc-API文档-中文(简体)-英语-对照版....

    lucene-spatial-extras-6.6.0-API文档-中英对照版.zip

    赠送源代码:lucene-spatial-extras-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras-6.6.0.pom; 包含翻译后的API文档:lucene-spatial-extras-6.6.0-javadoc-API文档-中文(简体)-英语-对照版....

    lucene-backward-codecs-7.2.1-API文档-中英对照版.zip

    赠送源代码:lucene-backward-codecs-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-backward-codecs-7.2.1.pom; 包含翻译后的API文档:lucene-backward-codecs-7.2.1-javadoc-API文档-中文(简体)-英语-对照...

    lucene-backward-codecs-6.6.0-API文档-中英对照版.zip

    赠送源代码:lucene-backward-codecs-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-backward-codecs-6.6.0.pom; 包含翻译后的API文档:lucene-backward-codecs-6.6.0-javadoc-API文档-中文(简体)-英语-对照...

    lucene-backward-codecs-6.6.0-API文档-中文版.zip

    赠送源代码:lucene-backward-codecs-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-backward-codecs-6.6.0.pom; 包含翻译后的API文档:lucene-backward-codecs-6.6.0-javadoc-API文档-中文(简体)版.zip; ...

    lucene-core-7.2.1-API文档-中文版.zip

    赠送源代码:lucene-core-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.2.1.pom; 包含翻译后的API文档:lucene-core-7.2.1-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.lucene:lucene...

    lucene-suggest-6.6.0-API文档-中文版.zip

    赠送源代码:lucene-suggest-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-suggest-6.6.0.pom; 包含翻译后的API文档:lucene-suggest-6.6.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache....

    lucene-highlighter-6.6.0-API文档-中文版.zip

    赠送源代码:lucene-highlighter-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-highlighter-6.6.0.pom; 包含翻译后的API文档:lucene-highlighter-6.6.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:org...

    lucene-core-6.6.0-API文档-中文版.zip

    赠送源代码:lucene-core-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-6.6.0.pom; 包含翻译后的API文档:lucene-core-6.6.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.lucene:lucene...

    lucene-sandbox-7.2.1-API文档-中文版.zip

    赠送源代码:lucene-sandbox-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-sandbox-7.2.1.pom; 包含翻译后的API文档:lucene-sandbox-7.2.1-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache....

    lucene-core-6.6.0-API文档-中英对照版.zip

    赠送源代码:lucene-core-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-6.6.0.pom; 包含翻译后的API文档:lucene-core-6.6.0-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.apache....

Global site tag (gtag.js) - Google Analytics