/** * @see org.opencms.search.I_CmsIndexer#newInstance(org.opencms.file.CmsObject, org.opencms.report.I_CmsReport, org.opencms.search.CmsSearchIndex) */ public I_CmsIndexer newInstance(CmsObject cms, I_CmsReport report, CmsSearchIndex index) { CmsVfsIndexer indexer = null; try { indexer = getClass().newInstance(); indexer.m_cms = cms; indexer.m_report = report; indexer.m_index = index; } catch (Exception e) { LOG.error( Messages.get().getBundle().key( Messages.ERR_INDEXSOURCE_INDEXER_CLASS_NAME_2, getClass().getName(), CmsVfsIndexer.class), e); } return indexer; }
/** * Sets the search index to use for the search. <p> * * @param index the search index to use for the search to set. * * @throws CmsIllegalArgumentException if null is given as argument */ public void setSearchIndex(CmsSearchIndex index) throws CmsIllegalArgumentException { if (index == null) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_INDEX_NULL_0)); } m_index = index; }
/** * Sets the search index to use for the search. <p> * * @param index the search index to use for the search to set. * * @throws CmsIllegalArgumentException if null is given as argument */ public void setSearchIndex(CmsSearchIndex index) throws CmsIllegalArgumentException { if (index == null) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_INDEX_NULL_0)); } m_index = index; }
/** * @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_CmsSearchDocument#addSearchField(org.opencms.search.fields.CmsSearchField, java.lang.String) */ public void addSearchField(CmsSearchField field, String value) { if (field instanceof CmsLuceneField) { add(((CmsLuceneField)field).createField(value)); } else { throw (new CmsRuntimeException( Messages.get().container(Messages.LOG_INVALID_FIELD_CLASS_1, field.getClass().getName()))); } }
/** * Adds a document type.<p> * * @param documentType a document type */ public void addDocumentTypeConfig(CmsSearchDocumentType documentType) { m_documentTypeConfigs.add(documentType); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key( Messages.INIT_SEARCH_DOC_TYPES_2, documentType.getName(), documentType.getClassName())); } }
/** * @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); }
/** * Sets the timeout to abandon threads indexing a resource as a String.<p> * * @param value the timeout in milliseconds */ public void setTimeout(String value) { try { setTimeout(Long.parseLong(value)); } catch (Exception e) { LOG.error( Messages.get().getBundle().key(Messages.LOG_PARSE_TIMEOUT_FAILED_2, value, new Long(DEFAULT_TIMEOUT)), e); setTimeout(DEFAULT_TIMEOUT); } }
/** * Adds a document type.<p> * * @param documentType a document type */ public void addDocumentTypeConfig(CmsSearchDocumentType documentType) { m_documentTypeConfigs.add(documentType); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info( Messages.get().getBundle().key( Messages.INIT_SEARCH_DOC_TYPES_2, documentType.getName(), documentType.getClassName())); } }
/** * Removes all indexes included in the given list (which must contain the name of an index to remove).<p> * * @param indexNames the names of the index to remove */ public void removeSearchIndexes(List<String> indexNames) { Iterator<String> i = indexNames.iterator(); while (i.hasNext()) { String indexName = i.next(); // get the search index by name CmsSearchIndex index = getIndex(indexName); if (index != null) { // remove the index removeSearchIndex(index); } else { if (LOG.isWarnEnabled()) { LOG.warn(Messages.get().getBundle().key(Messages.LOG_NO_INDEX_WITH_NAME_1, indexName)); } } } }
/** * Sets the maximum number of modifications before a commit in the search index is triggered as a string.<p> * * @param value the maximum number of modifications to set */ public void setMaxModificationsBeforeCommit(String value) { try { setMaxModificationsBeforeCommit(Integer.parseInt(value)); } catch (Exception e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_PARSE_MAXCOMMIT_FAILED_2, value, new Integer(DEFAULT_MAX_MODIFICATIONS_BEFORE_COMMIT)), e); setMaxModificationsBeforeCommit(DEFAULT_MAX_MODIFICATIONS_BEFORE_COMMIT); } }
/** * Sets the max. excerpt length as a String.<p> * * @param maxExcerptLength the max. excerpt length to set */ public void setMaxExcerptLength(String maxExcerptLength) { try { setMaxExcerptLength(Integer.parseInt(maxExcerptLength)); } catch (Exception e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_PARSE_EXCERPT_LENGTH_FAILED_2, maxExcerptLength, new Integer(DEFAULT_EXCERPT_LENGTH)), e); setMaxExcerptLength(DEFAULT_EXCERPT_LENGTH); } }
/** * Sets the maximum age a text extraction result is kept in the cache (in hours) as a String.<p> * * @param extractionCacheMaxAge the maximum age for a text extraction result to set */ public void setExtractionCacheMaxAge(String extractionCacheMaxAge) { try { setExtractionCacheMaxAge(Float.parseFloat(extractionCacheMaxAge)); } catch (NumberFormatException e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_PARSE_EXTRACTION_CACHE_AGE_FAILED_2, extractionCacheMaxAge, new Float(DEFAULT_EXTRACTION_CACHE_MAX_AGE)), e); setExtractionCacheMaxAge(DEFAULT_EXTRACTION_CACHE_MAX_AGE); } }
/** * Sets the update frequency of the offline indexer in milliseconds.<p> * * @param offlineUpdateFrequency the update frequency in milliseconds to set */ public void setOfflineUpdateFrequency(String offlineUpdateFrequency) { try { setOfflineUpdateFrequency(Long.parseLong(offlineUpdateFrequency)); } catch (Exception e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_PARSE_OFFLINE_UPDATE_FAILED_2, offlineUpdateFrequency, new Long(DEFAULT_OFFLINE_UPDATE_FREQNENCY)), e); setOfflineUpdateFrequency(DEFAULT_OFFLINE_UPDATE_FREQNENCY); } }
/** * Sets the timeout to abandon threads indexing a resource as a String.<p> * * @param value the timeout in milliseconds */ public void setTimeout(String value) { try { setTimeout(Long.parseLong(value)); } catch (Exception e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_PARSE_TIMEOUT_FAILED_2, value, new Long(DEFAULT_TIMEOUT)), e); setTimeout(DEFAULT_TIMEOUT); } }
/** * Sets the maximal wait time for offline index updates after edit operations.<p> * * @param maxIndexWaitTime the maximal wait time to set in milliseconds */ public void setMaxIndexWaitTime(String maxIndexWaitTime) { try { setMaxIndexWaitTime(Long.parseLong(maxIndexWaitTime)); } catch (Exception e) { LOG.error( Messages.get().getBundle().key( Messages.LOG_PARSE_MAX_INDEX_WAITTIME_FAILED_2, maxIndexWaitTime, new Long(DEFAULT_MAX_INDEX_WAITTIME)), e); setMaxIndexWaitTime(DEFAULT_MAX_INDEX_WAITTIME); } }
/** * Sets the update frequency of the offline indexer in milliseconds.<p> * * @param offlineUpdateFrequency the update frequency in milliseconds to set */ public void setOfflineUpdateFrequency(String offlineUpdateFrequency) { try { setOfflineUpdateFrequency(Long.parseLong(offlineUpdateFrequency)); } catch (Exception e) { LOG.error( Messages.get().getBundle().key( Messages.LOG_PARSE_OFFLINE_UPDATE_FAILED_2, offlineUpdateFrequency, new Long(DEFAULT_OFFLINE_UPDATE_FREQNENCY)), e); setOfflineUpdateFrequency(DEFAULT_OFFLINE_UPDATE_FREQNENCY); } }
/** * Sets the query to search for. <p> * * The decoding here is tailored for query strings that are * additionally manually UTF-8 encoded at client side (javascript) to get around an * issue with special chars in applications that use non- UTF-8 encoding * (e.g. ISO-8859-1) OpenCms applications. It is not recommended to use this with * front ends that don't encode manually as characters like sole "%" (without number suffix) * will cause an Exception.<p> * * @param query the query to search for to set */ public void setQuery(String query) { // for use with widgets the exception is thrown here to enforce the error message next to the widget if (query.trim().length() < getQueryLength()) { throw new CmsIllegalArgumentException( Messages.get().container(Messages.ERR_QUERY_TOO_SHORT_1, new Integer(getQueryLength()))); } m_query = query; }
/** * Sets the maximum number of modifications before a commit in the search index is triggered as a string.<p> * * @param value the maximum number of modifications to set */ public void setMaxModificationsBeforeCommit(String value) { try { setMaxModificationsBeforeCommit(Integer.parseInt(value)); } catch (Exception e) { LOG.error( Messages.get().getBundle().key( Messages.LOG_PARSE_MAXCOMMIT_FAILED_2, value, new Integer(DEFAULT_MAX_MODIFICATIONS_BEFORE_COMMIT)), e); setMaxModificationsBeforeCommit(DEFAULT_MAX_MODIFICATIONS_BEFORE_COMMIT); } }