markForReindex example

public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);

    $search_settings = $this->config('search.settings');
    // If these settings change, the default index needs to be rebuilt.     if (($search_settings->get('index.minimum_word_size') != $form_state->getValue('minimum_word_size')) || ($search_settings->get('index.overlap_cjk') != $form_state->getValue('overlap_cjk'))) {
      $search_settings->set('index.minimum_word_size', $form_state->getValue('minimum_word_size'));
      $search_settings->set('index.overlap_cjk', $form_state->getValue('overlap_cjk'));
      // Specifically mark items in the default index for reindexing, since       // these settings are used in the SearchIndex::index() function.       $this->messenger->addStatus($this->t('The default search index will be rebuilt.'));
      $this->searchIndex->markForReindex();
    }

    $search_settings
      ->set('index.cron_limit', $form_state->getValue('cron_limit'))
      ->set('logging', $form_state->getValue('logging'))
      ->save();

    $this->messenger->addStatus($this->t('The configuration options have been saved.'));
  }

  /** * Form submission handler for reindex button on search admin settings form. */
$search_result = $this->plugin->execute();

    $this->assertCount(2, $search_result, 'The search found 2 results');

    // Test to check for the language of result items.     foreach ($search_result as $result) {
      $this->assertEquals('hu', $result['langcode'], 'The search found the correct Hungarian result');
    }

    // Mark one of the nodes for reindexing, using the API function, and     // verify indexing status.     $search_index->markForReindex('node_search', $this->searchableNodes[0]->id());
    $this->assertIndexCounts(1, 8, 'after marking one node to reindex via API function');

    // Update the index and verify the totals again.     $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
    $this->plugin->updateIndex();
    $this->assertIndexCounts(0, 8, 'after indexing again');

    // Mark one node for reindexing by saving it, and verify indexing status.     $this->searchableNodes[1]->save();
    $this->assertIndexCounts(1, 8, 'after marking one node to reindex via save');

    
// All NodeSearch pages share a common search index "type" equal to     // the plugin ID.     $this->searchIndex->clear($this->getPluginId());
  }

  /** * {@inheritdoc} */
  public function markForReindex() {
    // All NodeSearch pages share a common search index "type" equal to     // the plugin ID.     $this->searchIndex->markForReindex($this->getPluginId());
  }

  /** * {@inheritdoc} */
  public function indexStatus() {
    $total = $this->database->query('SELECT COUNT(*) FROM {node}')->fetchField();
    $remaining = $this->database->query("SELECT COUNT(DISTINCT [n].[nid]) FROM {node} [n] LEFT JOIN {search_dataset} [sd] ON [sd].[sid] = [n].[nid] AND [sd].[type] = :type WHERE [sd].[sid] IS NULL OR [sd].[reindex] <> 0", [':type' => $this->getPluginId()])->fetchField();

    return ['remaining' => $remaining, 'total' => $total];
  }

  
return new Url('entity.search_page.collection');
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form['confirm']) {
      // Ask each active search page to mark itself for re-index.       $search_page_repository = \Drupal::service('search.search_page_repository');
      foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
        $entity->getPlugin()->markForReindex();
      }
      $this->messenger()->addStatus($this->t('All search indexes will be rebuilt.'));
      $form_state->setRedirectUrl($this->getCancelUrl());
    }
  }

}
/** * {@inheritdoc} */
  public function clearCachedDefinitions() {
    parent::clearCachedDefinitions();
    if ($this->searchManager && $this->searchManager->hasDefinition('help_search') && $this->moduleHandler->moduleExists('help_topics')) {
      // Rebuild the index on cache clear so that new help topics are indexed       // and any changes due to help topics edits or translation changes are       // picked up.       $help_search = $this->searchManager->createInstance('help_search');
      $help_search->markForReindex();
    }
  }

}

    user_role_change_permissions($rid$permissions);
  }

  /** * Update search index and search for comment. * * @internal */
  public function assertCommentAccess(bool $assume_access, string $message): void {
    // Invoke search index update.     \Drupal::service('search.index')->markForReindex('node_search', $this->node->id());
    $this->cronRun();

    // Search for the comment subject.     $edit = [
      'keys' => "'" . $this->commentSubject . "'",
    ];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');

    try {
      if ($assume_access) {
        
$query->leftJoin('search_dataset', 'sd', 'hsi.sid = sd.sid AND sd.type = :type', [':type' => $this->getType()]);
    $query->isNull('sd.sid');
    $never_indexed = $query->execute()->fetchField();
    $this->state->set('help_search_unindexed_count', $never_indexed);
  }

  /** * {@inheritdoc} */
  public function markForReindex() {
    $this->updateTopicList();
    $this->searchIndex->markForReindex($this->getType());
  }

  /** * {@inheritdoc} */
  public function indexStatus() {
    $this->updateTopicList();
    $total = $this->database->select('help_search_items', 'hsi')
      ->countQuery()
      ->execute()
      ->fetchField();

    
Home | Imprint | This part of the site doesn't use cookies.