List of usage examples for org.apache.lucene.store NIOFSDirectory NIOFSDirectory
public NIOFSDirectory(Path path) throws IOException
From source file:calliope.search.AeseSearch.java
License:Open Source License
/** * Build the entire Lucene index from scratch * @param langCode the language code// ww w.jav a 2 s. c o m */ public static void buildIndex(String langCode) throws AeseException { try { String[] docIDs = Connector.getConnection().listCollection(Database.CORTEX); Analyzer analyzer = createAnalyzer(langCode); File home = new File(System.getProperty("user.home")); indexLocation = new File(home, ".calliope"); if (!indexLocation.exists()) indexLocation.mkdir(); AeseSearch.index = new NIOFSDirectory(indexLocation); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_45, analyzer); IndexWriter w = new IndexWriter(index, config); for (int i = 0; i < docIDs.length; i++) { addCorTextoIndex(docIDs[i], w); } w.close(); } catch (Exception e) { throw new AeseException(e); } }
From source file:cn.hbu.cs.esearch.index.DefaultDirectoryManager.java
License:Apache License
@Override public Directory getDirectory(boolean create) throws IOException { if (!directory.exists() && create) { // create the parent directory directory.mkdirs();//from w w w .j av a 2 s. c om } if (create) { IndexSignature sig = null; if (directory.exists()) { sig = getCurrentIndexSignature(); } if (sig == null) { File directoryFile = new File(directory, INDEX_DIRECTORY); sig = new IndexSignature(null); try { saveSignature(sig, directoryFile); } catch (IOException e) { throw e; } } } FSDirectory dir = null; switch (mode) { case SIMPLE: dir = new SimpleFSDirectory(directory); break; case NIO: dir = new NIOFSDirectory(directory); break; case MMAP: dir = new MMapDirectory(directory); break; } LOGGER.info("created Directory: " + dir); return dir; }
From source file:com.bluedragon.search.collection.Collection.java
License:Open Source License
private void setDirectory() throws IOException { if (directory != null) return;/*from ww w . ja va 2s.com*/ if (Constants.WINDOWS) { directory = new SimpleFSDirectory(FileSystems.getDefault().getPath(collectionpath)); } else { directory = new NIOFSDirectory(FileSystems.getDefault().getPath(collectionpath)); } File touchFile = new File(collectionpath, "openbd.created"); if (touchFile.exists()) created = touchFile.lastModified(); else created = System.currentTimeMillis(); }
From source file:com.globalsight.ling.tm2.lucene.LuceneCache.java
License:Apache License
/** * For one dir searcher/*ww w.j a v a 2 s .c o m*/ * * @param path */ public static LuceneCache getLuceneCache(File path) throws IOException { if (path == null) { return null; } String p = path.getPath(); if (cache.containsKey(p)) { LuceneCache lc = cache.get(p); return lc; } NIOFSDirectory dir = new NIOFSDirectory(path); if (dir != null && DirectoryReader.indexExists(dir)) { // if (IndexWriter.isLocked(dir)) // { // IndexWriter.unlock(dir); // } // clean lock // dir.clearLock(name); IndexReader iR = DirectoryReader.open(dir); IndexSearcher iS = new IndexSearcher(iR); LuceneCache lc = new LuceneCache(p, iR, iS); iR.addReaderClosedListener(lc); cache.put(p, lc); return lc; } else { return null; } }
From source file:com.knowgate.lucene.Indexer.java
License:Open Source License
/** * Open Lucene Directory//from w w w .j av a2 s .c o m * @param sDirectoryPath String Full path to Directory location. * Use a disk path for opening a NIOFSDirectory o preffix the * path with bdb:// for opening a Berkely DB DbDirectory like "bdb:///opt/storage/db/" * @throws IOException * @since 7.0 */ public static Directory openDirectory(String sDirectoryPath) throws IOException { Directory oDir; if (sDirectoryPath.startsWith("bdb://")) { oDir = DBDirectory.open(sDirectoryPath.substring(6)); } else if (sDirectoryPath.startsWith("file://")) { oDir = new NIOFSDirectory(new File(sDirectoryPath.substring(7))); } else { oDir = new NIOFSDirectory(new File(sDirectoryPath)); } return oDir; }
From source file:com.knowgate.lucene.Indexer.java
License:Open Source License
public static void add(String sTableName, String sDirectory, String sAnalyzer, Map oKeywords, Map oTexts, Map oUnStored) throws ClassNotFoundException, IOException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, InstantiationException, NullPointerException { if (!allowedTable(sTableName)) throw new IllegalArgumentException("Table name must be k_bugs or k_newsmsgs or k_mime_msgs"); if (null == sDirectory) throw new NoSuchFieldException("Cannot find luceneindex property"); File oDir = new File(sDirectory); if (!oDir.exists()) { FileSystem oFS = new FileSystem(); try {// w ww . ja v a2s . com oFS.mkdirs(sDirectory); } catch (Exception e) { throw new IOException(e.getClass().getName() + " " + e.getMessage()); } } Class oAnalyzer = Class.forName((sAnalyzer == null) ? DEFAULT_ANALYZER : sAnalyzer); NIOFSDirectory oFsDir = new NIOFSDirectory(new File(sDirectory)); IndexWriter oIWrt = new IndexWriter(oFsDir, (Analyzer) oAnalyzer.newInstance(), IndexWriter.MaxFieldLength.LIMITED); add(oIWrt, oKeywords, oTexts, oUnStored); oIWrt.close(); oFsDir.close(); }
From source file:com.knowgate.lucene.Indexer.java
License:Open Source License
/** * Delete a document with a given GUID/*from w w w.j a v a2 s .c om*/ * @param sTableName k_bugs, k_newsmsgs or k_mime_msgs * @param oProps Properties Collection containing luceneindex directory * @param sGuid Document GUID * @return Number of documents deleted * @throws IllegalArgumentException If sTableName is not one of { k_bugs, k_newsmsgs, k_mime_msgs } * @throws NoSuchFieldException If luceneindex property is not found at oProps * @throws IllegalAccessException * @throws IOException * @throws NullPointerException If sGuid is <b>null</b> */ public static int delete(String sTableName, String sWorkArea, Properties oProps, String sGuid) throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException, IOException, NullPointerException { if (null == sGuid) throw new NullPointerException("Document GUID may not be null"); if (!allowedTable(sTableName)) throw new IllegalArgumentException("Table name must be k_bugs or k_newsmsgs or k_mime_msgs"); String sDirectory = oProps.getProperty("luceneindex"); if (null == sDirectory) throw new NoSuchFieldException("Cannot find luceneindex property"); sDirectory = Gadgets.chomp(sDirectory, File.separator) + sTableName.toLowerCase() + File.separator + sWorkArea; File oDir = new File(sDirectory); if (!oDir.exists()) { FileSystem oFS = new FileSystem(); try { oFS.mkdirs(sDirectory); } catch (Exception e) { throw new IOException(e.getClass().getName() + " " + e.getMessage()); } } // fi NIOFSDirectory oFsDir = new NIOFSDirectory(new File(sDirectory)); IndexReader oReader = IndexReader.open(oFsDir); int iDeleted = oReader.deleteDocuments(new Term("guid", sGuid)); oReader.close(); oFsDir.close(); return iDeleted; }
From source file:com.meltmedia.cadmium.search.SearchContentPreprocessor.java
License:Apache License
@Override public synchronized void processFromDirectory(String metaDir) throws Exception { SearchHolder newStagedSearcher = new SearchHolder(); indexDir = new File(metaDir, "lucene-index"); dataDir = new File(metaDir).getParentFile(); newStagedSearcher.directory = new NIOFSDirectory(indexDir); IndexWriter iwriter = null;/* w w w. ja v a 2s.c om*/ try { iwriter = new IndexWriter(newStagedSearcher.directory, new IndexWriterConfig(Version.LUCENE_43, analyzer).setRAMBufferSizeMB(5)); iwriter.deleteAll(); writeIndex(iwriter, dataDir); } finally { IOUtils.closeQuietly(iwriter); iwriter = null; } newStagedSearcher.indexReader = DirectoryReader.open(newStagedSearcher.directory); SearchHolder oldStage = stagedSearch; stagedSearch = newStagedSearcher; if (oldStage != null) { oldStage.close(); } log.info("About to call processSearchPreprocessors()"); processSearchPreprocessors(newStagedSearcher.indexReader, analyzer, "content"); }
From source file:com.tilab.ca.sse.core.lucene.LuceneManager.java
License:Open Source License
public static Directory pickDirectory(File indexDir) throws IOException { LOG.debug("[pickDirectory] - BEGIN"); Directory directory;//from w w w. j a v a 2 s .c o m if (System.getProperty("os.name").equals("Linux") && System.getProperty("os.arch").contains("64")) { directory = new MMapDirectory(indexDir); } else if (System.getProperty("os.name").equals("Linux")) { directory = new NIOFSDirectory(indexDir); } else { directory = FSDirectory.open(indexDir); } LOG.debug("[pickDirectory] - END"); return directory; }
From source file:com.vmware.xenon.services.common.LuceneDocumentIndexBackupService.java
License:Open Source License
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); }//from w w w . j a v a 2s. c om } }