@SuppressWarnings( "ResultOfMethodCallIgnored" ) @Override public Directory open( File dir ) throws IOException { dir.mkdirs(); FSDirectory directory = USE_DEFAULT_DIRECTORY_FACTORY ? FSDirectory.open( dir.toPath() ) : new NIOFSDirectory( dir.toPath() ); return new NRTCachingDirectory( directory, MAX_MERGE_SIZE_MB, MAX_CACHED_MB ); }
/** Just like {@link #open(Path)}, but allows you to * also specify a custom {@link LockFactory}. */ public static FSDirectory open(Path path, LockFactory lockFactory) throws IOException { if (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); } }
public void open() throws Exception { if ( !directory.exists() && !directory.mkdirs() ) { throw new IOException("Could not make: " + directory); } IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE); niofsDirectory = new NIOFSDirectory(directory, new SingleInstanceLockFactory()); writer = new IndexWriter(niofsDirectory, conf); }
public LogSearch(File file) throws Exception { this.file = file; directory = new NIOFSDirectory(file, new NativeFSLockFactory()); reader = IndexReader.open(directory); searcher = new IndexSearcher(reader); }
@Override public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, InternalLuceneIndex index, PartitionedRegion userRegion, IndexRepository oldRepository, PartitionedRepositoryManager partitionedRepositoryManager) throws IOException { final IndexRepository repo; if (oldRepository != null) { oldRepository.cleanup(); } LuceneRawIndex indexForRaw = (LuceneRawIndex) index; BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId); Directory dir = null; if (indexForRaw.withPersistence()) { String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId); File location = new File(index.getName(), bucketLocation); if (!location.exists()) { location.mkdirs(); } dir = new NIOFSDirectory(location.toPath()); } else { dir = new RAMDirectory(); } IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer()); IndexWriter writer = new IndexWriter(dir, config); return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "", indexForRaw); } }
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException { final String storeType = indexSettings.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.FS.getSettingsKey()); if (IndexModule.Type.FS.match(storeType)) { final IndexModule.Type type = IndexModule.defaultStoreType(IndexModule.NODE_STORE_ALLOW_MMAPFS.get(indexSettings.getNodeSettings())); switch (type) { case MMAPFS: return new MMapDirectory(location, lockFactory); case SIMPLEFS: return new SimpleFSDirectory(location, lockFactory); case NIOFS: return new NIOFSDirectory(location, lockFactory); default: throw new AssertionError("unexpected built-in store type [" + type + "]"); } } else if (IndexModule.Type.SIMPLEFS.match(storeType)) { return new SimpleFSDirectory(location, lockFactory); } else if (IndexModule.Type.NIOFS.match(storeType)) { return new NIOFSDirectory(location, lockFactory); } else if (IndexModule.Type.MMAPFS.match(storeType)) { return new MMapDirectory(location, lockFactory); } throw new IllegalArgumentException("No directory found for type [" + storeType + "]"); }
private Directory newDefaultDir(Path location, final MMapDirectory mmapDir, LockFactory lockFactory) throws IOException { return new FileSwitchDirectory(PRIMARY_EXTENSIONS, mmapDir, new NIOFSDirectory(location, lockFactory), true) { @Override public String[] listAll() throws IOException { // Avoid doing listAll twice: return mmapDir.listAll(); } }; } }
public DocumentAccess(String indexDir, int keywordProximity) throws IOException{ this.searcher = new IndexSearcher(DirectoryReader.open(new NIOFSDirectory(new File(indexDir)))); this.keywordProximity = keywordProximity; }
public void open(File indexDirectory, Analyzer analyzer) throws IOException { if (indexDirectory != null) { indexReader = DirectoryReader.open(new NIOFSDirectory(indexDirectory.toPath())); } else { indexReader = DirectoryReader.open(new NIOFSDirectory(new File("./indexDirectory").toPath())); } indexSearcher = new IndexSearcher(indexReader); this.analyzer = analyzer; }
@Override protected Directory createDirectory(Properties parameters) throws IOException { if (parameters.containsKey(LuceneSail.LUCENE_DIR_KEY)) { return new NIOFSDirectory(Paths.get(parameters.getProperty(LuceneSail.LUCENE_DIR_KEY))); } else return super.createDirectory(parameters); } }
public static boolean indexExists(String pageIndex) { try { return DirectoryReader.indexExists(new NIOFSDirectory(Paths.get( pageIndex))); } catch (IOException e) { e.printStackTrace(); } return false; }
public static boolean indexExists(String pageIndex) { try { return DirectoryReader.indexExists(new NIOFSDirectory(new File( pageIndex))); } catch (IOException e) { e.printStackTrace(); } return false; }
@Override protected Directory createDirectory(Properties parameters) throws IOException { if (parameters.containsKey(LuceneSail.LUCENE_DIR_KEY)) { return new NIOFSDirectory(new File(parameters.getProperty(LuceneSail.LUCENE_DIR_KEY))); } else return super.createDirectory(parameters); } }
public static boolean indexExists(String pageIndex) { try { return DirectoryReader.indexExists(new NIOFSDirectory(Paths.get( pageIndex))); } catch (IOException e) { e.printStackTrace(); } return false; }
private Directory createDirectory(int shardId, String basePath, String tableId) throws AnalyticsIndexException { String path = this.generateDirPath(shardId, basePath, tableId); try { return new NIOFSDirectory(Paths.get(path)); } catch (Exception e) { throw new AnalyticsIndexException("Error in creating directory: " + e.getMessage(), e); } }
/** 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); } }
/** Just like {@link #open(Path)}, but allows you to * also specify a custom {@link LockFactory}. */ public static FSDirectory open(Path path, LockFactory lockFactory) throws IOException { if (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); } }
/** Just like {@link #open(Path)}, but allows you to * also specify a custom {@link LockFactory}. */ public static FSDirectory open(Path path, LockFactory lockFactory) throws IOException { if (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); } }
/** Just like {@link #open(Path)}, but allows you to * also specify a custom {@link LockFactory}. */ public static FSDirectory open(Path path, LockFactory lockFactory) throws IOException { if (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); } }
private void copyInMemoryLuceneIndexToDirectory(IndexCommit commit, Path directoryPath) throws IOException { Directory from = commit.getDirectory(); try (Directory to = new NIOFSDirectory(directoryPath)) { for (String filename : commit.getFileNames()) { to.copyFrom(from, filename, filename, IOContext.DEFAULT); } } }