/** * Returns <code>true</code> if an index exists at the specified directory. * If the directory does not exist or if there is no index in it. * <code>false</code> is returned. * @param directory the directory to check for an index * @return <code>true</code> if an index exists; <code>false</code> otherwise */ public static boolean indexExists(String directory) { return indexExists(new File(directory)); }
/** * Returns <code>true</code> if an index exists at the specified directory. * If the directory does not exist or if there is no index in it. * <code>false</code> is returned. * @param directory the directory to check for an index * @return <code>true</code> if an index exists; <code>false</code> otherwise */ public static boolean indexExists(String directory) { return indexExists(new File(directory)); }
/** * @return isIndexed * @throws IOException */ public boolean isIndexed() throws IOException { return IndexReader.indexExists(getIndexDir()); }
@Override protected IndexReader openIndexReaderForDelete() throws IOException { if (IndexReader.indexExists(_directory)) { return IndexReader.open(_directory, false); } else { return null; } }
public Object run() throws Exception { spellIndexDirectory = handler.getDirectoryManager().getDirectory("spellchecker"); if (IndexReader.indexExists(spellIndexDirectory)) { lastRefresh = System.currentTimeMillis(); } return null; } });
@Override public List<RepositoryInfo> getLoaded(final List<RepositoryInfo> repos) { final List<RepositoryInfo> toRet = new ArrayList<RepositoryInfo>(repos.size()); for (final RepositoryInfo repo : repos) { File loc = new File(getDefaultIndexLocation(), repo.getId()); // index folder try { if (loc.exists() && new File(loc, "timestamp").exists() && IndexReader.indexExists(new SimpleFSDirectory(loc))) { toRet.add(repo); } } catch (IOException ex) { LOGGER.log(Level.FINER, "Index Not Available: " +repo.getId() + " at: " + loc.getAbsolutePath(), ex); } } return toRet; }
private void init(Directory d, Analyzer a, boolean closeDir, IndexDeletionPolicy deletionPolicy, boolean autoCommit, int maxFieldLength) throws CorruptIndexException, LockObtainFailedException, IOException { if (IndexReader.indexExists(d)) { init(d, a, false, closeDir, deletionPolicy, autoCommit, maxFieldLength); } else { init(d, a, true, closeDir, deletionPolicy, autoCommit, maxFieldLength); } }
private void init(Directory d, Analyzer a, boolean closeDir, IndexDeletionPolicy deletionPolicy, boolean autoCommit, int maxFieldLength) throws CorruptIndexException, LockObtainFailedException, IOException { if (IndexReader.indexExists(d)) { init(d, a, false, closeDir, deletionPolicy, autoCommit, maxFieldLength); } else { init(d, a, true, closeDir, deletionPolicy, autoCommit, maxFieldLength); } }
private void postInit() throws IOException { this.queryAnalyzer = new StandardAnalyzer(Version.LUCENE_35); // get rid of any locks that may have been left by previous (crashed) // sessions if (IndexWriter.isLocked(directory)) { logger.info("unlocking directory {}", directory); IndexWriter.unlock(directory); } // do some initialization for new indices if (!IndexReader.indexExists(directory)) { logger.info("creating new Lucene index in directory {}", directory); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_35, analyzer); indexWriterConfig.setOpenMode(OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, indexWriterConfig); writer.close(); } }
@Override protected IndexReader openIndexReaderForDelete() throws IOException { Directory directory = _dirMgr.getDirectory(true); if (IndexReader.indexExists(directory)){ return IndexReader.open(directory, _deletionPolicy, false); } else{ return null; } }
@Override public boolean isIndexed() throws IOException { return IndexReader.indexExists(getIndexDir()) && super.isIndexed(); }
public boolean isIndexCreated() { try { return IndexReader.indexExists(configuration.getDirectory()); } catch (final IOException e) { ///CLOVER:OFF throw new RuntimeIOException(e); ///CLOVER:ON } } }
private IndexReader getArchive(ZoieSystem<R, D> zoie) throws CorruptIndexException, IOException { String dirName = zoie.getAdminMBean().getIndexDir(); Directory dir = new SimpleFSDirectory(new File(dirName)); IndexReader reader = null; if (IndexReader.indexExists(dir)) { reader = IndexReader.open(dir, true); } else { log.info("empty index " + dirName); reader = null; } return reader; } }
public Object doInTransaction() throws CompassException { Directory dir = spellCheckStore.openDirectory(spellIndexSubContext, subIndex); close(subIndex); try { if (!IndexReader.indexExists(dir)) { IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); writer.close(); } } catch (IOException e) { throw new SearchEngineException("Failed to verify spell index for sub index [" + subIndex + "]", e); } refresh(subIndex); return null; } });
private void openWriter() { try { IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzers); config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); Directory index = getIndex(indexDirPath); if(IndexReader.indexExists(index)) config.setOpenMode(IndexWriterConfig.OpenMode.APPEND); config.setRAMBufferSizeMB(BUFFERRAMSIZE); indexer = new Indexer(config, index); } catch (IOException e) { e.printStackTrace(); } }
private void openWriter(Language language) { try { IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, AnalyzerFactory.getAnalyzer(language)); config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); Directory index = getIndex(indexPathToWrite); if(IndexReader.indexExists(index)) config.setOpenMode(IndexWriterConfig.OpenMode.APPEND); config.setRAMBufferSizeMB(BUFFERRAMSIZE); indexer = new Indexer(config, index); } catch (IOException e) { e.printStackTrace(); } }
private void openWriter(Language language) { try { IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, getAnalyzer(language)); config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); Directory index = getIndex(indexDirPath); if(IndexReader.indexExists(index)) config.setOpenMode(IndexWriterConfig.OpenMode.APPEND); config.setRAMBufferSizeMB(BUFFERRAMSIZE); indexer = new Indexer(config, index); } catch (IOException e) { e.printStackTrace(); } }
public LucisSearcher get() { try { Directory d = directory(); if (!IndexReader.indexExists(d)) { d = EmptyDirectory.get(); } final IndexReader reader = IndexReader.open(d); return new DefaultLucisSearcher(reader); } catch (Exception e) { throw new IndexNotAvailableException(e); } } }
public synchronized boolean indexExists(String subContext, String subIndex) throws SearchEngineException { boolean closeDir = !directoryExists(subContext, subIndex); Directory dir = openDirectory(subContext, subIndex); Boolean retVal = directoryStore.indexExists(unwrapDir(dir)); if (retVal != null) { return retVal; } try { retVal = IndexReader.indexExists(dir); } catch (IOException e) { return false; } if (closeDir) { closeDirectory(dir, subContext, subIndex); } return retVal; }
private void newReader() throws IOException { lastDirectory = getDirectory(); if (lastDirectory == null || !IndexReader.indexExists(lastDirectory)) { log().warn("Directory [%s] does not exist. Using empty one.", lastDirectory); newEmpty(); } else { try { setManagedReader(IndexReader.open(lastDirectory)); } catch (IOException e) { log().error(e, "Unable to open directory [%s]. Using empty one.", lastDirectory); newEmpty(); } } }