get('SolrReindexImmediateHandler'); } /** * @param SS_HTTPRequest $request */ public function run($request) { parent::run($request); // Reset state $originalState = SearchVariant::current_state(); $this->doReindex($request); SearchVariant::activate_state($originalState); } /** * @param SS_HTTPRequest $request */ protected function doReindex($request) { $class = $request->getVar('class'); $index = $request->getVar('index'); //find the index classname by IndexName // this is for when index names do not match the class name (this can be done by overloading getIndexName() on // indexes if ($index && !ClassInfo::exists($index)) { foreach(ClassInfo::subclassesFor('SolrIndex') as $solrIndexClass) { $reflection = new ReflectionClass($solrIndexClass); //skip over abstract classes if (!$reflection->isInstantiable()) { continue; } //check the indexname matches the index passed to the request if (!strcasecmp(singleton($solrIndexClass)->getIndexName(), $index)) { //if we match, set the correct index name and move on $index = $solrIndexClass; break; } } } // Deprecated reindex mechanism $start = $request->getVar('start'); if ($start !== null) { // Run single batch directly $indexInstance = singleton($index); $state = json_decode($request->getVar('variantstate'), true); $this->runFrom($indexInstance, $class, $start, $state); return; } // Check if we are re-indexing a single group // If not using queuedjobs, we need to invoke Solr_Reindex as a separate process // Otherwise each group is processed via a SolrReindexGroupJob $groups = $request->getVar('groups'); $handler = $this->getHandler(); if ($groups) { // Run grouped batches (id % groups = group) $group = $request->getVar('group'); $indexInstance = singleton($index); $state = json_decode($request->getVar('variantstate'), true); $handler->runGroup($this->getLogger(), $indexInstance, $state, $class, $groups, $group); return; } // If run at the top level, delegate to appropriate handler $self = get_class($this); $handler->triggerReindex($this->getLogger(), $this->config()->recordsPerRequest, $self, $class); } /** * @deprecated since version 2.0.0 */ protected function runFrom($index, $class, $start, $variantstate) { DeprecationTest_Deprecation::notice('2.0.0', 'Solr_Reindex now uses a new grouping mechanism'); // Set time limit and state increase_time_limit_to(); SearchVariant::activate_state($variantstate); // Generate filtered list $items = DataList::create($class) ->limit($this->config()->recordsPerRequest, $start); // Add child filter $classes = $index->getClasses(); $options = $classes[$class]; if (!$options['include_children']) { $items = $items->filter('ClassName', $class); } // Process selected records in this class $this->getLogger()->info("Adding $class"); foreach ($items->sort("ID") as $item) { $this->getLogger()->debug($item->ID); // See SearchUpdater_ObjectHandler::triggerReindex $item->triggerReindex(); $item->destroy(); } $this->getLogger()->info("Done"); } }