/** * Default constructor when called as cron job.<p> */ public CmsSearchManager() { m_documentTypes = new HashMap<String, I_CmsDocumentFactory>(); m_documentTypeConfigs = new ArrayList<CmsSearchDocumentType>(); m_analyzers = new HashMap<Locale, CmsSearchAnalyzer>(); m_indexes = new ArrayList<CmsSearchIndex>(); m_indexSources = new TreeMap<String, CmsSearchIndexSource>(); m_offlineHandler = new CmsSearchOfflineHandler(); m_extractionCacheMaxAge = DEFAULT_EXTRACTION_CACHE_MAX_AGE; m_maxExcerptLength = DEFAULT_EXCERPT_LENGTH; m_offlineUpdateFrequency = DEFAULT_OFFLINE_UPDATE_FREQNENCY; m_maxIndexWaitTime = DEFAULT_MAX_INDEX_WAITTIME; m_maxModificationsBeforeCommit = DEFAULT_MAX_MODIFICATIONS_BEFORE_COMMIT; m_fieldConfigurations = new HashMap<String, CmsSearchFieldConfiguration>(); // make sure we have a "standard" field configuration addFieldConfiguration(CmsLuceneFieldConfiguration.DEFAULT_STANDARD); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_START_SEARCH_CONFIG_0)); } }
/** * Updates all offline indexes for the given list of {@link CmsResource} objects.<p> * * @param resources a list of {@link CmsResource} objects to update in the offline indexes */ protected synchronized void reIndexResources(List<CmsResource> resources) { List<CmsPublishedResource> resourcesToIndex = new ArrayList<CmsPublishedResource>(resources.size()); Iterator<CmsResource> r = resources.iterator(); while (r.hasNext()) { CmsResource res = r.next(); CmsPublishedResource pubRes = new CmsPublishedResource(res); resourcesToIndex.add(pubRes); } if (resourcesToIndex.size() > 0) { // add the resources found to the offline index thread addResourcesToIndex(resourcesToIndex); } } }
/** * Initialize the offline index handler, require after an offline index has been added.<p> */ public void initOfflineIndexes() { // check which indexes are configured as offline indexes List<CmsSearchIndex> offlineIndexes = new ArrayList<CmsSearchIndex>(); Iterator<CmsSearchIndex> i = m_indexes.iterator(); while (i.hasNext()) { CmsSearchIndex index = i.next(); if (CmsSearchIndex.REBUILD_MODE_OFFLINE.equals(index.getRebuildMode())) { // this is an offline index offlineIndexes.add(index); } } m_offlineIndexes = offlineIndexes; m_offlineHandler.initialize(); }
reIndexResources(resources); break; case I_CmsEventListener.EVENT_RESOURCE_DELETED: reIndexResources(resourcesToDelete); break; case I_CmsEventListener.EVENT_RESOURCES_AND_PROPERTIES_MODIFIED: case I_CmsEventListener.EVENT_RESOURCES_MODIFIED: reIndexResources((List<CmsResource>)event.getData().get(I_CmsEventListener.KEY_RESOURCES)); break; default:
/** * Obtains the list of resource to update in the offline index, * then optimizes the list by removing duplicate entries.<p> * * @return the list of resource to update in the offline index */ protected List<CmsPublishedResource> getResourcesToIndex() { List<CmsPublishedResource> resourcesToIndex = m_handler.getResourcesToIndex(); List<CmsPublishedResource> result = new ArrayList<CmsPublishedResource>(resourcesToIndex.size()); Iterator<CmsPublishedResource> i = resourcesToIndex.iterator(); while (i.hasNext()) { Object o = i.next(); CmsPublishedResource pubRes = (CmsPublishedResource)o; int pos = result.indexOf(pubRes); if (pos < 0) { // resource not already contained in the update list result.add(pubRes); } else { CmsPublishedResource curRes = result.get(pos); if ((pubRes.getState() != curRes.getState()) || (pubRes.getMovedState() != curRes.getMovedState()) || !pubRes.getRootPath().equals(curRes.getRootPath())) { // resource already in the update list but new state is different, so also add this result.add(pubRes); } } } return result; }
/** * Implements the event listener of this class.<p> * * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent) */ public void cmsEvent(CmsEvent event) { switch (event.getType()) { case I_CmsEventListener.EVENT_PROPERTY_MODIFIED: case I_CmsEventListener.EVENT_RESOURCE_CREATED: case I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED: case I_CmsEventListener.EVENT_RESOURCE_MODIFIED: // a resource has been modified - offline indexes require (re)indexing List<CmsResource> resources = Collections.singletonList((CmsResource)event.getData().get( I_CmsEventListener.KEY_RESOURCE)); reIndexResources(resources); break; case I_CmsEventListener.EVENT_RESOURCES_AND_PROPERTIES_MODIFIED: case I_CmsEventListener.EVENT_RESOURCE_MOVED: case I_CmsEventListener.EVENT_RESOURCE_DELETED: case I_CmsEventListener.EVENT_RESOURCE_COPIED: case I_CmsEventListener.EVENT_RESOURCES_MODIFIED: // a list of resources has been modified - offline indexes require (re)indexing reIndexResources((List<CmsResource>)event.getData().get(I_CmsEventListener.KEY_RESOURCES)); break; default: // no operation } }
/** * Obtains the list of resource to update in the offline index, * then optimizes the list by removing duplicate entries.<p> * * @return the list of resource to update in the offline index */ protected List<CmsPublishedResource> getResourcesToIndex() { List<CmsPublishedResource> resourcesToIndex = m_handler.getResourcesToIndex(); List<CmsPublishedResource> result = new ArrayList<CmsPublishedResource>(resourcesToIndex.size()); // Reverse to always keep the last list entries Collections.reverse(resourcesToIndex); for (CmsPublishedResource pubRes : resourcesToIndex) { boolean addResource = true; for (CmsPublishedResource resRes : result) { if (pubRes.equals(resRes) && (pubRes.getState() == resRes.getState()) && (pubRes.getMovedState() == resRes.getMovedState()) && pubRes.getRootPath().equals(resRes.getRootPath())) { // resource already in the update list addResource = false; break; } } if (addResource) { result.add(pubRes); } } Collections.reverse(result); return changeStateOfMoveOriginsToDeleted(result); }
/** * Default constructor when called as cron job.<p> */ public CmsSearchManager() { m_documentTypes = new HashMap<String, I_CmsDocumentFactory>(); m_documentTypeConfigs = new ArrayList<CmsSearchDocumentType>(); m_analyzers = new HashMap<Locale, CmsSearchAnalyzer>(); m_indexes = new ArrayList<CmsSearchIndex>(); m_indexSources = new TreeMap<String, CmsSearchIndexSource>(); m_offlineHandler = new CmsSearchOfflineHandler(); m_extractionCacheMaxAge = DEFAULT_EXTRACTION_CACHE_MAX_AGE; m_maxExcerptLength = DEFAULT_EXCERPT_LENGTH; m_offlineUpdateFrequency = DEFAULT_OFFLINE_UPDATE_FREQNENCY; m_maxModificationsBeforeCommit = DEFAULT_MAX_MODIFICATIONS_BEFORE_COMMIT; m_fieldConfigurations = new HashMap<String, CmsSearchFieldConfiguration>(); // make sure we have a "standard" field configuration addFieldConfiguration(CmsSearchFieldConfiguration.DEFAULT_STANDARD); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_START_SEARCH_CONFIG_0)); } }
/** * Updates all offline indexes for the given list of {@link CmsResource} objects.<p> * * @param resources a list of {@link CmsResource} objects to update in the offline indexes */ protected synchronized void reIndexResources(List<CmsResource> resources) { List<CmsPublishedResource> resourcesToIndex = new ArrayList<CmsPublishedResource>(resources.size()); for (CmsResource res : resources) { CmsPublishedResource pubRes = new CmsPublishedResource(res); resourcesToIndex.add(pubRes); } if (resourcesToIndex.size() > 0) { // add the resources found to the offline index thread addResourcesToIndex(resourcesToIndex); } } }
/** * Initialize the offline index handler, require after an offline index has been added.<p> */ public void initOfflineIndexes() { // check which indexes are configured as offline indexes List<CmsSearchIndex> offlineIndexes = new ArrayList<CmsSearchIndex>(); Iterator<CmsSearchIndex> i = m_indexes.iterator(); while (i.hasNext()) { CmsSearchIndex index = i.next(); if (CmsSearchIndex.REBUILD_MODE_OFFLINE.equals(index.getRebuildMode())) { // this is an offline index offlineIndexes.add(index); } } m_offlineIndexes = offlineIndexes; m_offlineHandler.initialize(); }