/** * @see org.opencms.search.I_CmsIndexWriter#close() */ public void close() throws IOException { if ((m_index != null) && LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_INDEX_WRITER_MSG_CLOSE_2, m_index.getName(), m_index.getPath())); } m_indexWriter.close(); }
/** * @see org.opencms.search.I_CmsIndexWriter#commit() */ public void commit() throws IOException { if ((m_index != null) && LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_INDEX_WRITER_MSG_COMMIT_2, m_index.getName(), m_index.getPath())); } m_indexWriter.commit(); }
/** * @see org.opencms.search.I_CmsIndexWriter#optimize() * * As optimize is deprecated with Lucene 3.5, this implementation * actually calls {@link IndexWriter#forceMerge(int)}.<p> */ public void optimize() throws IOException { if ((m_index != null) && LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_INDEX_WRITER_MSG_OPTIMIZE_2, m_index.getName(), m_index.getPath())); } int oldPriority = Thread.currentThread().getPriority(); // we don't want the priority too low as the process should complete as fast as possible Thread.currentThread().setPriority(Thread.NORM_PRIORITY / 2); m_indexWriter.forceMerge(5); Thread.currentThread().setPriority(oldPriority); }
/** * Creates a new index writer based on the provided standard Lucene IndexWriter for the * provided OpenCms search index instance.<p> * * The OpenCms search instance is currently used only for improved logging of the * index operations.<p> * * @param indexWriter the standard Lucene IndexWriter to use as delegate * @param index the OpenCms search index instance this writer to supposed to write to */ public CmsLuceneIndexWriter(IndexWriter indexWriter, CmsSearchIndex index) { m_indexWriter = indexWriter; m_index = index; if ((m_index != null) && LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_INDEX_WRITER_MSG_CREATE_2, m_index.getName(), m_index.getPath())); } }
/** * @see org.opencms.search.I_CmsIndexWriter#updateDocument(java.lang.String, org.opencms.search.I_CmsSearchDocument) */ public void updateDocument(String rootPath, I_CmsSearchDocument document) throws IOException { Term pathTerm = new Term(CmsSearchField.FIELD_PATH, rootPath); if ((m_index != null) && LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key( Messages.LOG_INDEX_WRITER_MSG_DOC_UPDATE_3, rootPath, m_index.getName(), m_index.getPath())); } m_indexWriter.updateDocument(pathTerm, (Document)document.getDocument()); } }
/** * @see org.opencms.search.I_CmsIndexWriter#deleteDocument(org.opencms.db.CmsPublishedResource) */ public void deleteDocument(CmsPublishedResource resource) throws IOException { // search for an exact match on the document root path Term term = new Term(CmsSearchField.FIELD_PATH, resource.getRootPath()); if ((m_index != null) && LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key( Messages.LOG_INDEX_WRITER_MSG_DOC_DELETE_3, resource.getRootPath(), m_index.getName(), m_index.getPath())); } m_indexWriter.deleteDocuments(term); }
FSDirectory dir = null; try { File f = new File(getPath()); if (!f.exists()) { f = f.getParentFile(); dir = FSDirectory.open(Paths.get(getPath())); IndexWriterConfig indexConfig = new IndexWriterConfig(getAnalyzer()); } catch (IOException closeExeception) { throw new CmsIndexException( Messages.get().container(Messages.ERR_IO_INDEX_WRITER_OPEN_2, getPath(), getName()), e); Messages.get().container(Messages.ERR_IO_INDEX_WRITER_OPEN_2, getPath(), getName()), e);
/** * Shuts down the search index.<p> * * This will close the local Lucene index searcher instance.<p> */ public void shutDown() { // close the index writer if (m_indexWriter != null) { try { m_indexWriter.commit(); m_indexWriter.close(); } catch (IOException e) { LOG.error( Messages.get().getBundle().key(Messages.LOG_IO_INDEX_WRITER_CLOSE_2, getPath(), getName()), e); } } indexSearcherClose(); if (m_analyzer != null) { m_analyzer.close(); } if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_INDEX_1, getName())); } }
if ((searchIndex.getSources() == null) || (searchIndex.getPath() == null)) { if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) { try {
/** * Reopens the index search reader for this index, required after the index has been changed.<p> * * @see #indexSearcherOpen(String) */ protected synchronized void indexSearcherUpdate() { IndexSearcher oldSearcher = m_indexSearcher; if ((oldSearcher != null) && (oldSearcher.getIndexReader() != null)) { // in case there is an index searcher available close it try { if (oldSearcher.getIndexReader() instanceof DirectoryReader) { IndexReader newReader = DirectoryReader.openIfChanged( (DirectoryReader)oldSearcher.getIndexReader()); if (newReader != null) { m_indexSearcher = new IndexSearcher(newReader); m_indexSearcher.setSimilarity(m_sim); indexSearcherClose(oldSearcher); } } } catch (Exception e) { LOG.error(Messages.get().getBundle().key(Messages.ERR_INDEX_SEARCHER_REOPEN_1, getName()), e); } } else { // make sure we end up with an open index searcher / reader indexSearcherOpen(getPath()); } }
if ((searchIndex.getSources() == null) || (searchIndex.getPath() == null)) { if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) { try {
Messages.get().container(Messages.LOG_IO_INDEX_WRITER_CLOSE_2, getPath(), getName()), e);
File indexPath = new File(index.getPath()); boolean indexLocked = true; indexLocked = IndexWriter.isLocked(index.getPath()); } catch (Exception e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_IO_INDEX_READER_OPEN_2, index.getPath(), index.getName()), e); try { IndexWriter.unlock(FSDirectory.getDirectory(index.getPath())); } catch (Exception e) { try { IndexWriter.unlock(FSDirectory.getDirectory(index.getPath())); } catch (Exception e) {
Messages.LOG_IO_INDEX_WRITER_COMMIT_2, index.getName(), index.getPath()), e);
Messages.LOG_IO_INDEX_WRITER_COMMIT_2, index.getName(), index.getPath()), e);
Messages.LOG_IO_INDEX_WRITER_COMMIT_2, indexer.getIndex().getName(), indexer.getIndex().getPath()), e);