List of usage examples for org.apache.lucene.store FSDirectory listAll
@Override
public String[] listAll() throws IOException
From source file:edu.ucla.cs.scai.linkedspending.index.QueryIndexWithLucene.java
public QueryIndexWithLucene(String path) { System.out.println("Loading index..."); HashMap<String, Analyzer> analyzerMap = new HashMap<>(); analyzerMap.put("label", new EnglishAnalyzer(CharArraySet.EMPTY_SET)); analyzerMap.put("uri", new WhitespaceAnalyzer()); analyzerMap.put("type", new WhitespaceAnalyzer()); analyzer = new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer(), analyzerMap); if (!path.endsWith(File.separator)) { path += File.separator;/*w w w.j a v a2s . c om*/ } directory = new RAMDirectory(); FSDirectory tempDirectory; System.out.println("Loading index from disk..."); try { tempDirectory = FSDirectory.open(Paths.get(path)); for (String file : tempDirectory.listAll()) { directory.copyFrom(tempDirectory, file, file, IOContext.DEFAULT); } } catch (IOException ex) { Logger.getLogger(QueryIndexWithLucene.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:it.agilelab.bigdata.spark.search.impl.BigChunksRAMDirectory.java
License:Apache License
private BigChunksRAMDirectory(FSDirectory dir, boolean closeDir, IOContext context) throws IOException { this();/*from w ww. j a v a2 s . co m*/ for (String file : dir.listAll()) { if (!Files.isDirectory(dir.getDirectory().resolve(file))) { copyFrom(dir, file, file, context); } } if (closeDir) { dir.close(); } }
From source file:org.opencms.search.CmsSearchIndex.java
License:Open Source License
/** * Creates a backup of this index for optimized re-indexing of the whole content.<p> * //from www . j a v a2 s . c o m * @return the path to the backup folder, or <code>null</code> in case no backup was created */ protected String createIndexBackup() { if (!isBackupReindexing()) { // if no backup is generated we don't need to do anything return null; } // check if the target directory already exists File file = new File(getPath()); if (!file.exists()) { // index does not exist yet, so we can't backup it return null; } String backupPath = getPath() + "_backup"; try { // open file directory for Lucene FSDirectory oldDir = FSDirectory.open(file); FSDirectory newDir = FSDirectory.open(new File(backupPath)); for (String fileName : oldDir.listAll()) { oldDir.copy(newDir, fileName, fileName); } } catch (Exception e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_IO_INDEX_BACKUP_CREATE_3, getName(), getPath(), backupPath), e); backupPath = null; } return backupPath; }
From source file:org.tightblog.service.LuceneIndexer.java
License:Apache License
private Directory getFSDirectory(boolean delete) { FSDirectory directory = null; try {/* w w w. ja v a 2 s. co m*/ directory = FSDirectory.open(new File(indexDir).toPath()); if (delete) { // clear old files String[] files = directory.listAll(); for (String fileName : files) { File file = new File(indexDir, fileName); if (!file.delete()) { throw new IOException("couldn't delete " + fileName); } } } } catch (IOException e) { log.error("Problem accessing index directory", e); } return directory; }