/** * Truncate and rebuild the tx_solr_indexqueue_item table. This is the most * complete way to force reindexing, or to build the Index Queue for the * first time. The Index Queue initialization is site-specific. * * @param Tx_Solr_Site $site The site to initialize * @param string $indexingConfigurationName Name of a specific * indexing configuration * @return array An array of booleans, each representing whether the * initialization for an indexing configuration was successful */ public function initialize(Tx_Solr_Site $site, $indexingConfigurationName = '') { $indexingConfigurations = array(); $initializationStatus = array(); if (empty($indexingConfigurationName)) { $solrConfiguration = $site->getSolrConfiguration(); $indexingConfigurations = $this->getTableIndexingConfigurations($solrConfiguration); } else { $indexingConfigurations[] = $indexingConfigurationName; } foreach ($indexingConfigurations as $indexingConfigurationName) { $initializationStatus[$indexingConfigurationName] = $this->initializeIndexingConfiguration($site, $indexingConfigurationName); } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessIndexQueueInitialization'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessIndexQueueInitialization'] as $classReference) { $indexQueueInitializationPostProcessor = t3lib_div::getUserObj($classReference); if ($indexQueueInitializationPostProcessor instanceof Tx_Solr_IndexQueueInitializationPostProcessor) { $indexQueueInitializationPostProcessor->postProcessIndexQueueInitialization($site, $indexingConfigurations, $initializationStatus); } else { throw new UnexpectedValueException(get_class($indexQueueInitializationPostProcessor) . ' must implement interface Tx_Solr_IndexQueueInitializationPostProcessor', 1345815561); } } } return $initializationStatus; }
protected function logInitialization($initializationQuery) { $solrConfiguration = $this->site->getSolrConfiguration(); $logSeverity = -1; $logData = array('site' => $this->site->getLabel(), 'indexing configuration name' => $this->indexingConfigurationName, 'type' => $this->type, 'query' => $initializationQuery, 'rows' => $GLOBALS['TYPO3_DB']->sql_affected_rows()); if ($GLOBALS['TYPO3_DB']->sql_errno()) { $logSeverity = 3; $logData['error'] = $GLOBALS['TYPO3_DB']->sql_errno() . ': ' . $GLOBALS['TYPO3_DB']->sql_error(); } if ($solrConfiguration['logging.']['indexing.']['indexQueueInitialization']) { t3lib_div::devLog('Index Queue initialized for indexing configuration ' . $this->indexingConfigurationName, 'solr', $logSeverity, $logData); } }
/** * Removes documents of the selected types from the index. * * @return bool TRUE if clean up was successful, FALSE on error */ protected function cleanUpIndex() { $cleanUpResult = TRUE; $solrConfiguration = $this->site->getSolrConfiguration(); $solrServers = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_ConnectionManager')->getConnectionsBySite($this->site); $typesToCleanUp = array(); foreach ($this->indexingConfigurationsToReIndex as $indexingConfigurationName) { $type = Tx_Solr_IndexQueue_Queue::getTableToIndexByIndexingConfigurationName($solrConfiguration, $indexingConfigurationName); $typesToCleanUp[] = $type; } foreach ($solrServers as $solrServer) { // make sure not-yet committed documents are removed, too $solrServer->commit(); $deleteQuery = 'type:(' . implode(' OR ', $typesToCleanUp) . ')' . ' AND siteHash:' . $this->site->getSiteHash(); $solrServer->deleteByQuery($deleteQuery); $response = $solrServer->commit(FALSE, FALSE, FALSE); if ($response->getHttpStatus() != 200) { $cleanUpResult = FALSE; break; } } return $cleanUpResult; }