lucene4.7源码研究之索引建立过程(1)
2015-04-17 16:58
381 查看
Directory整体流程还是比较简单的,图片借用
以NIOFSDirectory为例
整个open的过程其实就是在简单的定位lockFactory中setLockDir(),并且设置lockID
BaseDirectory
Directory directory = FSDirectory.open(file);
/** Creates an FSDirectory instance, trying to pick the * best implementation given the current environment. * The directory returned uses the {@link NativeFSLockFactory}. * * <p>Currently this returns {@link MMapDirectory} for most Solaris * and Windows 64-bit JREs, {@link NIOFSDirectory} for other * non-Windows JREs, and {@link SimpleFSDirectory} for other * JREs on Windows. It is highly recommended that you consult the * implementation's documentation for your platform before * using this method. * * <p><b>NOTE</b>: this method may suddenly change which * implementation is returned from release to release, in * the event that higher performance defaults become * possible; if the precise implementation is important to * your application, please instantiate it directly, * instead. For optimal performance you should consider using * {@link MMapDirectory} on 64 bit JVMs. * * <p>See <a href="#subclasses">above</a> */ public static FSDirectory open(File path) throws IOException { return open(path, null);//使用默认锁工厂 } /** Just like {@link #open(File)}, but allows you to * also specify a custom {@link LockFactory}. */ public static FSDirectory open(File path, LockFactory lockFactory) throws IOException { if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { return new MMapDirectory(path, lockFactory); } else if (Constants.WINDOWS) { return new SimpleFSDirectory(path, lockFactory); } else { return new NIOFSDirectory(path, lockFactory); } }
以NIOFSDirectory为例
/** Create a new NIOFSDirectory for the named location. * * @param path the path of the directory * @param lockFactory the lock factory to use, or null for the default * ({@link NativeFSLockFactory}); * @throws IOException if there is a low-level I/O error */ public NIOFSDirectory(File path, LockFactory lockFactory) throws IOException { super(path, lockFactory); }
/** Create a new FSDirectory for the named location (ctor for subclasses). * @param path the path of the directory * @param lockFactory the lock factory to use, or null for the default * ({@link NativeFSLockFactory}); * @throws IOException if there is a low-level I/O error */ protected FSDirectory(File path, LockFactory lockFactory) throws IOException { // new ctors use always NativeFSLockFactory as default: if (lockFactory == null) { lockFactory = new NativeFSLockFactory(); } directory = getCanonicalPath(path);//获取path绝对路径 if (directory.exists() && !directory.isDirectory()) throw new NoSuchDirectoryException("file '" + directory + "' exists but is not a directory"); setLockFactory(lockFactory);//设置锁工厂 }
/** * Create a NativeFSLockFactory instance, with null (unset) * lock directory. When you pass this factory to a {@link FSDirectory} * subclass, the lock directory is automatically set to the * directory itself. Be sure to create one instance for each directory * your create! */ public NativeFSLockFactory() { this((File) null);//工厂没有设置路径 }
@Override public void setLockFactory(LockFactory lockFactory) throws IOException { super.setLockFactory(lockFactory); // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed // in index dir. If no index dir is given, set ourselves if (lockFactory instanceof FSLockFactory) { final FSLockFactory lf = (FSLockFactory) lockFactory; final File dir = lf.getLockDir();//因为(File)null,所以dir为null // if the lock factory has no lockDir set, use the this directory as lockDir if (dir == null) { lf.setLockDir(directory);//使用我们设置的directory lf.setLockPrefix(null); } else if (dir.getCanonicalPath().equals(directory.getCanonicalPath())) { lf.setLockPrefix(null); } } }
整个open的过程其实就是在简单的定位lockFactory中setLockDir(),并且设置lockID
BaseDirectory
@Override public String toString() { return getClass().getSimpleName() + '@' + Integer.toHexString(hashCode()) + " lockFactory=" + getLockFactory(); }
相关文章推荐
- lucene4.7源码研究之索引建立过程(3)-2
- lucene4.7源码研究之索引建立过程(2)
- lucene4.7源码研究之索引建立过程(3)-1
- lucene(全文搜索)_根据内容建立索引_源码下载
- lucene(全文搜索)_建立索引_根据关键字全文搜索_源码下载
- lucene建立索引的过程
- Lucene 3.0.0的细节初窥(2)-研究在索引过程中的缓存
- 针对Lucene 建立索引过程与搜索过程耗费时间的矛盾一点思路
- lucene索引建立的效率研究
- Lucene建立索引的过程学习
- lucene 建立索引的过程
- lucene4.5源码分析系列:索引的创建过程
- Lucene源码解析--索引创建过程
- lucene源码-倒排索引的读过程
- lucene建立索引的过程
- lucene4.7索引源码研究之Segment元文件
- Openstack Cinder中建立volume过程的源码解析(5)----以及taskflow相关解析
- 利用lucene对整个数据库建立索引
- 通过Lucene索引文件学习Lucene索引过程
- live555源码研究(十)------在编译过程中遇到的问题及解决方法