@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 ); }
static synchronized void setIndexReaderSearcher() { try{ FSDirectory index = NIOFSDirectory.open(indexDir.toPath()); if(reader == null){ reader = DirectoryReader.open(index); searcher = new IndexSearcher(reader); }else{ DirectoryReader newreader = DirectoryReader.openIfChanged(reader); if(newreader != null) { reader.close(); reader = newreader; searcher = new IndexSearcher(reader); } } }catch(IOException e){ throw new RuntimeException(e); } }
@Override public IndexInput openInput(String name, IOContext context) throws IOException { ensureOpen(); ensureCanRead(name); Path path = getDirectory().resolve(name); FileChannel fc = FileChannel.open(path, StandardOpenOption.READ); return new NIOFSIndexInput("NIOFSIndexInput(path=\"" + path + "\")", fc, context); }
/** Creates an IndexInput for the file with the given name. */ @Override public IndexInput openInput(String name, IOContext context) throws IOException { ensureOpen(); Path path = getDirectory().resolve(name); FileChannel fc = FileChannel.open(path, StandardOpenOption.READ); return new NIOFSIndexInput("NIOFSIndexInput(path=\"" + path + "\")", fc, context); }
/** Creates an IndexInput for the file with the given name. */ @Override public IndexInput openInput(String name, IOContext context) throws IOException { ensureOpen(); return new NIOFSIndexInput(new File(getDirectory(), name), context, getReadChunkSize()); }
public IndexInput openInput(String name, int bufferSize) throws IOException { ensureOpen(); return new NIOFSIndexInput(new File(getFile(), name), bufferSize); }
public static String toString(Directory directory) { if (directory instanceof NIOFSDirectory) { NIOFSDirectory niofsDirectory = (NIOFSDirectory)directory; return "niofs(" + niofsDirectory.getDirectory() + ")"; } if (directory instanceof MMapDirectory) { MMapDirectory mMapDirectory = (MMapDirectory)directory; return "mmapfs(" + mMapDirectory.getDirectory() + ")"; } if (directory instanceof SimpleFSDirectory) { SimpleFSDirectory simpleFSDirectory = (SimpleFSDirectory)directory; return "simplefs(" + simpleFSDirectory.getDirectory() + ")"; } if (directory instanceof FileSwitchDirectory) { FileSwitchDirectory fileSwitchDirectory = (FileSwitchDirectory) directory; return "default(" + toString(fileSwitchDirectory.getPrimaryDir()) + "," + toString(fileSwitchDirectory.getSecondaryDir()) + ")"; } return directory.toString(); }
/** Creates an IndexInput for the file with the given name. */ @Override public IndexInput openInput(String name, IOContext context) throws IOException { ensureOpen(); Path path = getDirectory().resolve(name); FileChannel fc = FileChannel.open(path, StandardOpenOption.READ); return new NIOFSIndexInput("NIOFSIndexInput(path=\"" + path + "\")", fc, context); }
public IndexInput openInput(String name, int bufferSize) throws IOException { ensureOpen(); return new NIOFSIndexInput(new File(getFile(), name), bufferSize); }
public static String toString(Directory directory) { if (directory instanceof NIOFSDirectory) { NIOFSDirectory niofsDirectory = (NIOFSDirectory)directory; return "niofs(" + niofsDirectory.getDirectory() + ")"; } if (directory instanceof MMapDirectory) { MMapDirectory mMapDirectory = (MMapDirectory)directory; return "mmapfs(" + mMapDirectory.getDirectory() + ")"; } if (directory instanceof SimpleFSDirectory) { SimpleFSDirectory simpleFSDirectory = (SimpleFSDirectory)directory; return "simplefs(" + simpleFSDirectory.getDirectory() + ")"; } if (directory instanceof FileSwitchDirectory) { FileSwitchDirectory fileSwitchDirectory = (FileSwitchDirectory) directory; return "default(" + toString(fileSwitchDirectory.getPrimaryDir()) + "," + toString(fileSwitchDirectory.getSecondaryDir()) + ")"; } return directory.toString(); }
/** 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 openIndexes(boolean overwrite) throws IOException { if (directory == null) { try { if (path == null) directory = new RAMDirectory(); else { //directory = new MMapDirectory(new File(config.getPath())); // as per http://wiki.apache.org/lucene-java/ImproveSearchingSpeed // we use NIOFSDirectory, provided we're not on Windows if (Utils.isWindowsOS()) directory = FSDirectory.open(new File(path)); else directory = NIOFSDirectory.open(new File(path)); } IndexWriterConfig cfg = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer); cfg.setOpenMode(overwrite ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND); iwriter = new IndexWriter(directory, cfg); iwriter.commit(); // so that the searcher doesn't fail } catch (IndexNotFoundException e) { if (!overwrite) { // the index was not there, so make a new one directory = null; // ensure we really do try again openIndexes(true); } else throw new DukeException(e); } } }
@Override public IndexInputSlicer createSlicer(final String name, final IOContext context) throws IOException { ensureOpen(); final File path = new File(getDirectory(), name); final RandomAccessFile descriptor = new RandomAccessFile(path, "r"); return new Directory.IndexInputSlicer() { @Override public void close() throws IOException { descriptor.close(); } @Override public IndexInput openSlice(String sliceDescription, long offset, long length) { return new NIOFSIndexInput(sliceDescription, path, descriptor, descriptor.getChannel(), offset, length, BufferedIndexInput.bufferSize(context), getReadChunkSize()); } @Override public IndexInput openFullSlice() { try { return openSlice("full-slice", 0, descriptor.length()); } catch (IOException ex) { throw new RuntimeException(ex); } } }; }
@Override public IndexInput openInput(String name, IOContext context) throws IOException { ensureOpen(); ensureCanRead(name); Path path = getDirectory().resolve(name); FileChannel fc = FileChannel.open(path, StandardOpenOption.READ); return new NIOFSIndexInput("NIOFSIndexInput(path=\"" + path + "\")", fc, context); }
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); }
/** * Gets the current IndexSearcher. * * @return IndexSearcher * @throws IOException * Signals that an I/O exception has occurred. */ public static Directory getDirectoryIndex( ) throws IOException { return NIOFSDirectory.open( Paths.get( _strIndex ) ); }
public LogSearch(File file) throws Exception { this.file = file; directory = new NIOFSDirectory(file, new NativeFSLockFactory()); reader = IndexReader.open(directory); searcher = new IndexSearcher(reader); }
public DocumentIndexer(String indexDir) throws IOException { Directory dir = NIOFSDirectory.open(new File(indexDir)); writer = new IndexWriter(dir, config); try { reader = DirectoryReader.open(dir); } catch (IndexNotFoundException e) { // Silently ignore, means we are indexing at a new location } startingTime = System.currentTimeMillis(); }
@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); } }
public DocumentIndexer(String indexDir) throws IOException { System.out.println( NAME + ": opening index directory '" + indexDir + "'." ); Directory dir = NIOFSDirectory.open(new File(indexDir)); writer = new IndexWriter(dir, config); try { reader = DirectoryReader.open(dir); } catch (IndexNotFoundException e) { // Silently ignore, means we are indexing at a new location System.err.println( NAME + ": directory '" + dir + "' not found; creating new index." ); // Console console = System.console(); // String input = console.readLine("Press enter to continue:"); // if (!input.equals("")) // System.exit(-1); } startingTime = System.currentTimeMillis(); }