/**
  * Generates the list of indexes to process for the dirty items
  * 
  * @return array
  */
 protected function prepareIndexes()
 {
     $originalState = SearchVariant::current_state();
     $dirtyIndexes = array();
     $dirty = $this->getSource();
     $indexes = FullTextSearch::get_indexes();
     foreach ($dirty as $base => $statefulids) {
         if (!$statefulids) {
             continue;
         }
         foreach ($statefulids as $statefulid) {
             $state = $statefulid['state'];
             $ids = $statefulid['ids'];
             SearchVariant::activate_state($state);
             // Ensure that indexes for all new / updated objects are included
             $objs = DataObject::get($base)->byIDs(array_keys($ids));
             foreach ($objs as $obj) {
                 foreach ($ids[$obj->ID] as $index) {
                     if (!$indexes[$index]->variantStateExcluded($state)) {
                         $indexes[$index]->add($obj);
                         $dirtyIndexes[$index] = $indexes[$index];
                     }
                 }
                 unset($ids[$obj->ID]);
             }
             // Generate list of records that do not exist and should be removed
             foreach ($ids as $id => $fromindexes) {
                 foreach ($fromindexes as $index) {
                     if (!$indexes[$index]->variantStateExcluded($state)) {
                         $indexes[$index]->delete($base, $id, $state);
                         $dirtyIndexes[$index] = $indexes[$index];
                     }
                 }
             }
         }
     }
     SearchVariant::activate_state($originalState);
     return $dirtyIndexes;
 }
 /**
  * Send updates to the current search processor for execution
  * 
  * @param array $writes
  */
 public static function process_writes($writes)
 {
     foreach ($writes as $write) {
         // For every index
         foreach (FullTextSearch::get_indexes() as $index => $instance) {
             // If that index as a field from this class
             if (SearchIntrospection::is_subclass_of($write['class'], $instance->dependancyList)) {
                 // Get the dirty IDs
                 $dirtyids = $instance->getDirtyIDs($write['class'], $write['id'], $write['statefulids'], $write['fields']);
                 // Then add then then to the global list to deal with later
                 foreach ($dirtyids as $dirtyclass => $ids) {
                     if ($ids) {
                         if (!self::$processor) {
                             self::$processor = Injector::inst()->create('SearchUpdateProcessor');
                         }
                         self::$processor->addDirtyIDs($dirtyclass, $ids, $index);
                     }
                 }
             }
         }
     }
     // If we do have some work to do register the shutdown function to actually do the work
     // Don't do it if we're testing - there's no database connection outside the test methods, so we'd
     // just get errors
     $runningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     if (self::$processor && !self::$registered && !$runningTests) {
         register_shutdown_function(array("SearchUpdater", "flush_dirty_indexes"));
         self::$registered = true;
     }
 }
 /**
  * Get the list of index names we should process
  *
  * @return array
  */
 public function getAllIndexes()
 {
     if (empty($this->indexes)) {
         $indexes = FullTextSearch::get_indexes();
         $this->indexes = array_keys($indexes);
     }
     return $this->indexes;
 }
 static function get_indexes()
 {
     return FullTextSearch::get_indexes('SolrIndex');
 }