Process re-index for a given variant state and class

@param LoggerInterface $logger
@param SolrIndex $indexInstance
@param array $state Variant state
@param string $class
@param bool $includeSubclasses
@param int $batchSize
@param string $taskName
14259
protected function processVariant(
        LoggerInterface $logger,
        SolrIndex $indexInstance,
        $state,
        $class,
        $includeSubclasses,
        $batchSize,
        $taskName
    ) {
        // Set state
        SearchVariant::activate_state($state);

        // Count records
        $query = $class::get();
        if (!$includeSubclasses) {
            $query = $query->filter('ClassName', $class);
        }
        $total = $query->count();

        // Skip this variant if nothing to process, or if there are no records
        if ($total == 0 || $indexInstance->variantStateExcluded($state)) {
            // Remove all records in the current state, since there are no groups to process
            $logger->info("Clearing all records of type {$class} in the current state: " . json_encode($state));
            $this->clearRecords($indexInstance, $class);
            return;
        }

        // For each group, run processing
        $groups = (int)(($total + $batchSize - 1) / $batchSize);
        for ($group = 0; $group < $groups; $group++) {
            $this->processGroup($logger, $indexInstance, $state, $class, $groups, $group, $taskName);
        }
    }
577983
private void indexQuery(QueryEntry entry, ServerSessionContext session, CompletableFuture<QueryResponse> future) {
    // If the query index is greater than the session's last applied index, queue the request for handling once the
    // state machine is caught up.
    if (entry.getIndex() > session.getLastApplied()) {
      session.registerIndexQuery(entry.getIndex(), () -> applyQuery(entry, future));
    } else {
      applyQuery(entry, future);
    }
  }
381505
public function handle(Client $client, $oldIndex, $newIndex)
    {
        $classname = self::$crossIndexClassname;

        $classname::reindex(
            $client->getIndex($oldIndex),
            $client->getIndex($newIndex)
        );
    }
685390
def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
      return if algolia_without_auto_index_scope
      algolia_configurations.each do |options, settings|
        next if algolia_indexing_disabled?(options)
        next if options[:slave] || options[:replica]

        # fetch the master settings
        master_index = algolia_ensure_init(options, settings)
        master_settings = master_index.get_settings rescue {} # if master doesn't exist yet
        master_settings.merge!(JSON.parse(settings.to_settings.to_json)) # convert symbols to strings

        # remove the replicas of the temporary index
        master_settings.delete :slaves
        master_settings.delete 'slaves'
        master_settings.delete :replicas
        master_settings.delete 'replicas'

        # init temporary index
        index_name = algolia_index_name(options)
        tmp_options = options.merge({ :index_name => "#{index_name}.tmp" })
        tmp_options.delete(:per_environment) # already included in the temporary index_name
        tmp_settings = settings.dup
        tmp_index = algolia_ensure_init(tmp_options, tmp_settings, master_settings)

        algolia_find_in_batches(batch_size) do |group|
          if algolia_conditional_index?(tmp_options)
            # select only indexable objects
            group = group.select { |o| algolia_indexable?(o, tmp_options) }
          end
          objects = group.map { |o| tmp_settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o, tmp_options) }
          tmp_index.save_objects(objects)
        end

        move_task = SafeIndex.move_index(tmp_index.name, index_name)
        master_index.wait_task(move_task["taskID"]) if synchronous || options[:synchronous]
      end
      nil
    end
213503
public function loadPlugin($class, $forceRehash = true)
	{
		// a new class was added or the include failed so we rebuild the cache
		if (!isset($this->classPath[$class]) || !(include $this->classPath[$class])) {
			if ($forceRehash) {
				$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');
				foreach ($this->paths as $path=>$file) {
					$this->rebuildClassPathCache($path, $file);
				}
				if (isset($this->classPath[$class])) {
					include $this->classPath[$class];
				} else {
					throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
				}
			} else {
				throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
			}
		}
	}
5007
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newQ1 = (MtasSpanQuery) q1.rewrite(reader);
    MtasSpanQuery newQ2 = (MtasSpanQuery) q2.rewrite(reader);
    if (!newQ1.equals(q1) || !newQ2.equals(q2)) {
      return new MtasSpanNotQuery(newQ1, newQ2).rewrite(reader);
    } else {
      baseQuery = (SpanNotQuery) baseQuery.rewrite(reader);
      return super.rewrite(reader);
    }
  }
998662
private function pushCallerStatedClassName(StateInterface $state): ProxyInterface
    {
        $stateClass = \get_class($state);

        if (!isset($this->classesByStates[$stateClass])) {
            throw new \RuntimeException("Error, no original class name defined for $stateClass");
        }

        $this->callerStatedClassesStack->push($this->classesByStates[$stateClass]);

        return $this;
    }
267224
public function setLogger(LoggerInterface $logger):void{
		$this->logger = $logger;
		$this->driver->setLogger($logger);
		$this->query->setLogger($logger);
	}
1130740
public function run(State $state, Logger $logger)
    {
        $state->annotations;
        $state->classes;

        $dir = realpath($state->config->getExportDir());
        if (!$dir) {
            throw new RuntimeException('export dir does not exist');
        }

        $exportFile = $dir . '/' . $this->file;

        $logger->log(0, sprintf('save parsed result to %s', $exportFile));

        $content = print_r($state->classes, true) . PHP_EOL . print_r($state->annotations, true);

        file_put_contents($exportFile, $content);
    }
1059861
private function replaceMarkupsInFile(FileContext $context, State $state, Logger $logger)
    {
        $logger->log(1, sprintf('replace markups in <cyan>%s<reset>', $context->path));

        $state->currentFile = $context->path;

        $content = file_get_contents($context->path);
        $content = $this->replaceMarkupsInContent($content, $context, $state, $logger, true);

        file_put_contents($context->path, $content);
    }
507107
@SuppressWarnings("unchecked")
    private void performUpdate(final Subscriber<? super T> subscriber, State state)
            throws SQLException {
        if (subscriber.isUnsubscribed()) {
            return;
        }
        if (query.context().batchSize() > 1 && !query.context().isTransactionOpen()) {
            throw new SQLRuntimeException("batching can only be performed within a transaction");
        }
        int keysOption;
        if (query.returnGeneratedKeys()) {
            keysOption = Statement.RETURN_GENERATED_KEYS;
        } else {
            keysOption = Statement.NO_GENERATED_KEYS;
        }
        state.ps = state.con.prepareStatement(query.sql(), keysOption);
        Util.setParameters(state.ps, parameters, query.names());

        if (subscriber.isUnsubscribed())
            return;

        int count;
        try {
            debug("executing sql={}, parameters {}", query.sql(), parameters);
            if (state.ps instanceof PreparedStatementBatch
                    && parameters instanceof ArrayListFinal) {
                count = state.ps.executeUpdate();
                count += ((PreparedStatementBatch) state.ps).executeBatchRemaining();
            } else {
                count = state.ps.executeUpdate();
            }
            debug("executed ps={}", state.ps);
            if (query.returnGeneratedKeys()) {
                debug("getting generated keys");
                ResultSet rs = state.ps.getGeneratedKeys();
                debug("returned generated key result set {}", rs);
                state.rs = rs;
                Observable<Parameter> params = Observable.just(new Parameter(state));
                Observable<Object> depends = Observable.empty();
                Observable<T> o = new QuerySelect(QuerySelect.RETURN_GENERATED_KEYS, params,
                        depends, query.context(), query.context().resultSetTransform())
                                .execute(query.returnGeneratedKeysFunction());
                Subscriber<T> sub = createSubscriber(subscriber);
                o.unsafeSubscribe(sub);
            }
        } catch (SQLException e) {
            throw new SQLException("failed to execute sql=" + query.sql(), e);
        }
        if (!query.returnGeneratedKeys()) {
            // must close before onNext so that connection is released and is
            // available to a query that might process the onNext
            close(state);
            if (subscriber.isUnsubscribed())
                return;
            debug("onNext");
            subscriber.onNext((T) (Integer) count);
            complete(subscriber);
        }
    }
1089562
@SuppressWarnings("unchecked")
  private <T extends Indexer> T createIndexer(Class<T> indexerClass) {
    synchronized (indexerClass) {
      Indexer indexer = cache.get(indexerClass);
      if (indexer == null) {
        indexer = (Indexer) IntrospectionUtils.instantiateObject(indexerClass);
        cache.put(indexerClass, indexer);
      }
      return (T) indexer;
    }
  }
688325
private function addInheritedIndexes(ClassMetadata $subClass, ClassMetadata $parentClass)
    {
        if (! $parentClass->isMappedSuperclass) {
            return;
        }

        foreach (array('uniqueConstraints', 'indexes') as $indexType) {
            if (isset($parentClass->table[$indexType])) {
                foreach ($parentClass->table[$indexType] as $indexName => $index) {
                    if (isset($subClass->table[$indexType][$indexName])) {
                        continue; // Let the inheriting table override indices
                    }

                    $subClass->table[$indexType][$indexName] = $index;
                }
            }
        }
    }
1269830
def reindex(self, fq= [], **kwargs):
        '''
        
        '''
        for items in self._getter(fq=fq, **kwargs):
            self._putter(items)
        if type(self._dest) is SolrClient and self._dest_coll:
            self.log.info("Finished Indexing, sending a commit")
            self._dest.commit(self._dest_coll, openSearcher=True)
360939
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->title('Start ke_search indexer process');
        $indexerRunner = GeneralUtility::makeInstance(IndexerRunner::class);
        $indexerRunner->logger->log('notice', 'Indexer process started by command controller.');
        $indexerResponse = $indexerRunner->startIndexing(
            true, [], 'CLI'
        );

        if (strstr($indexerResponse, 'You can\'t start the indexer twice')) {
            $io->warning(
                'Indexing lock is set. You can\'t start the indexer process twice.' . chr(10) . chr(10)
                . 'If lock was not reset because of indexer errors you can use ke_search:removelock command.'
            );
        } else {

            // set custom style
            $titleStyle = new OutputFormatterStyle('blue', 'black', array('bold'));
            $output->getFormatter()->setStyle('title', $titleStyle);
            $warning = false;

            foreach (explode(chr(10), $indexerResponse) as $line) {

                // skip empty lines
                if (empty(strip_tags($line))) {
                    continue;
                }

                // format lines and catch warnings
                if (strstr($line, 'There were errors')) {
                    $warning = strip_tags(str_replace('[DANGER] ', '', $line));
                } else if (strstr($line, 'Index contains')) {
                    $io->writeln('<info>' . strip_tags($line) . '</info>');
                } else if (strstr($line, '<p><b>')) {
                    $io->writeln(chr(10) . '<title>' . strip_tags($line) . '</>');
                } else {
                    $io->writeln(strip_tags($line));
                }
            }

            if ($warning !== false) {
                $io->warning($warning);
            }

            $io->success('Indexer process completed.');
        }
    }
853802
protected function logIssue( $class, $checkMode, $file, $inProgressAutoloadArray, $generatingMode )
    {
        $conflictFile = ($checkMode === $generatingMode) ?
                        $inProgressAutoloadArray[$class] :
                        $this->existingAutoloadArrays[$checkMode][$class];

        if ( $generatingMode === self::MODE_KERNEL_OVERRIDE and $checkMode === self::MODE_KERNEL )
        {
            if ( $inProgressAutoloadArray !== null and array_key_exists( $class, $inProgressAutoloadArray ) )
            {
                return;
            }

            $message = "Class {$class}";
            $message .= " in file {$file}";
            $message .= " will override:\n";
            $message .= "{$conflictFile} ({$this->targetTable($checkMode)}/{$this->nameTable($checkMode)})";
            $this->log( $message );
        }
        else
        {
            $message = "Class {$class}";
            $message .= " in file {$file}";
            $message .= " is already defined in:\n";
            $message .= "{$conflictFile} ({$this->targetTable($checkMode)}/{$this->nameTable($checkMode)})";
            $message .= "\nThis class was not added to the autoload array.";
            $this->logWarning( $message );
        }
    }
1337349
private function beforeTask(
        string $logid,
        int $spanid,
        string $name,
        string $method,
        string $type,
        string $taskClass
    ) {
        $event = new BeforeTaskEvent(TaskEvent::BEFORE_TASK, $logid, $spanid, $name, $method, $type, $taskClass);
        App::trigger($event);
    }