/** * 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); if (directory.exists() && !directory.isDirectory()) throw new NoSuchDirectoryException("file '" + directory + "' exists but is not a directory"); setLockFactory(lockFactory); }
/** * Creates an FSDirectory in provided directory and initializes an index if not already existing. * * @param indexDir the directory where to write a new index * @param properties the configuration properties * @return the created {@code FSDirectory} instance * @throws IOException if an error */ public static FSDirectory createFSIndex(File indexDir, Properties properties) throws IOException { LockFactory lockFactory = createLockFactory(indexDir, properties); FSDirectoryType fsDirectoryType = FSDirectoryType.getType(properties); FSDirectory fsDirectory = fsDirectoryType.getDirectory(indexDir, null); // must use the setter (instead of using the constructor) to set the lockFactory, or Lucene will // throw an exception if it's different than a previous setting. fsDirectory.setLockFactory(lockFactory); log.debug("Initialize index: '{}'", indexDir.getAbsolutePath()); initializeIndexIfNeeded(fsDirectory); return fsDirectory; }