List of usage examples for org.apache.lucene.store RAMDirectory RAMDirectory
public RAMDirectory(LockFactory lockFactory)
From source file:minoe.SearchFiles.java
public SearchFiles(MetaDataController mdc) { this.metadata = mdc; try {//from w ww .j a va2s.co m // try loading index into memory directory = FSDirectory.getDirectory(index); ramDir = new RAMDirectory(directory); reader = IndexReader.open(ramDir); } catch (Exception ex) { System.out.println("Error loading index: " + ex.toString()); } catch (java.lang.OutOfMemoryError err) { // if there isn't memory available, then just read index from disk. try { directory = FSDirectory.getDirectory(index); reader = IndexReader.open(directory); } catch (IOException ex) { System.out.println("Error loading index: " + err.toString()); } } }
From source file:net.javacoding.xsearch.search.searcher.DefaultSearcherProvider.java
public boolean configure(File mainDir, File tempDir, DatasetConfiguration dc, boolean isInMemory) throws DataSourceException, IOException { this.isInMemorySearch = isInMemory; if (mainDir != null && mainDir.exists()) { mainDirectoryFile = mainDir;/*from w ww . j ava 2 s . c o m*/ } File tempIndexReadyFile = new File(tempDir, "ready"); if (tempDir != null && tempDir.exists() && tempIndexReadyFile.exists()) { tempDirectoryFile = tempDir; } if (isInMemorySearch) { try { if (tempDirectoryFile != null) { logger.info("Loading Temporary index into in memory for " + tempDirectoryFile + " ..."); tempDirectory = new RAMDirectory(tempDirectoryFile); logger.info("Loaded Temporary index into in memory for " + tempDirectoryFile); } if (mainDirectoryFile != null) { logger.info("Loading index into in memory for " + mainDirectoryFile + " ..."); mainDirectory = new RAMDirectory(mainDirectoryFile); logger.info("Loaded index into in memory for " + mainDirectoryFile); } logger.info("Successfully loaded index into in memory for " + mainDir); } catch (FileNotFoundException fnfe) { isInMemorySearch = false; logger.info("Failed to create in memory index for " + mainDir + ":" + fnfe.toString()); } catch (OutOfMemoryError oom) { isInMemorySearch = false; logger.warn("Index is too large! Falling back to disk based index..."); } } if (!isInMemorySearch) { if (tempDirectoryFile != null) { tempDirectory = FSDirectory.getDirectory(tempDirectoryFile); } if (mainDir != null && mainDir.exists()) { mainDirectory = FSDirectory.getDirectory(mainDir); } } initIndexReader(); if (licenseLevel <= 0) { licenseLevel = ServerConfiguration.getServerConfiguration().getAllowedLicenseLevel(); } if (_irs != null) { _irs.getSearcher().setSimilarity(dc.getSimilarity()); } else { return false; } return true; }
From source file:net.sf.lucis.core.impl.RAMStore.java
License:Apache License
public RAMStore(final Store<T> store) throws Exception { checkNotNull(store, "A source store must be provided."); this.checkpoint = store.getCheckpoint(); this.directory = new RAMDirectory(store.getDirectory()); }
From source file:org.alfresco.repo.search.impl.lucene.index.IndexInfo.java
License:Open Source License
private IndexReader buildReferenceCountingIndexReader(String id, long size) throws IOException { IndexReader reader;//from www .ja va2 s . c o m File location = new File(indexDirectory, id).getCanonicalFile(); double folderSize = getSizeInMb(location); if (IndexReader.indexExists(location)) { if ((size < maxDocsForInMemoryIndex) && (folderSize < maxRamInMbForInMemoryIndex)) { RAMDirectory rd = new RAMDirectory(location); reader = IndexReader.open(rd); } else { reader = IndexReader.open(location); } } else { reader = IndexReader.open(emptyIndex); } reader = ReferenceCountingReadOnlyIndexReaderFactory.createReader(id, reader, true, config); return reader; }