@Test public void multiIndexWithSimilarPaths() throws Exception{ LuceneIndexDefinition defn1 = LuceneIndexDefinition.newBuilder(root, idx.getNodeState(), "/content/a/en_us/oak:index/fooIndex").build(); LuceneIndexDefinition defn2 = LuceneIndexDefinition.newBuilder(root, idx.getNodeState(), "/content/b/en_us/oak:index/fooIndex").build(); FSDirectoryFactory factory = new FSDirectoryFactory(temporaryFolder.getRoot()); factory.newInstance(defn1, idx, ":data", false).close(); factory.newInstance(defn2, idx, ":data", false).close(); IndexRootDirectory idxDir = new IndexRootDirectory(temporaryFolder.getRoot()); List<LocalIndexDir> indexes = idxDir.getAllLocalIndexes(); assertEquals(2, indexes.size()); List<String> idxPaths = indexes.stream().map (LocalIndexDir::getJcrPath).collect(Collectors.toList()); assertThat(idxPaths, hasItems("/content/a/en_us/oak:index/fooIndex", "/content/b/en_us/oak:index/fooIndex")); }
@Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } FSDirectoryFactory(File baseDir); }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } FSDirectoryFactory(File baseDir); @Override Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder,
                                 String dirName, boolean reindex); @Override boolean remoteDirectory(); }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } FSDirectoryFactory(File baseDir); @Override Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder,
                                 String dirName, boolean reindex); @Override boolean remoteDirectory();  }