diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index fa1d080..f9cb26c 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -388,7 +388,7 @@ public function searchIndexClear() { /** * {@inheritdoc} */ - public function searchMarkForReindex() { + public function markForReindex() { // All NodeSearch pages share a common search index "type" equal to // the plugin ID. search_mark_for_reindex($this->getPluginId()); diff --git a/core/modules/search/src/Form/ReindexConfirm.php b/core/modules/search/src/Form/ReindexConfirm.php index d30c6a9..84948a2 100644 --- a/core/modules/search/src/Form/ReindexConfirm.php +++ b/core/modules/search/src/Form/ReindexConfirm.php @@ -34,7 +34,7 @@ public function getQuestion() { * Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription(). */ public function getDescription() { - return $this->t('The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed. This action cannot be undone.'); + return $this->t("This will re-index content in the search indexes of all active search pages. Searching will continue to work, but new content won't be indexed until all existing content has been re-indexed. This action cannot be undone."); } /** @@ -63,8 +63,12 @@ public function getCancelUrl() { */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($form['confirm']) { - search_mark_for_reindex(); - drupal_set_message($this->t('The index will be rebuilt.')); + // 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(); + } + drupal_set_message($this->t('All search indexes will be rebuilt.')); $form_state->setRedirectUrl($this->getCancelUrl()); } } diff --git a/core/modules/search/src/Plugin/SearchIndexingInterface.php b/core/modules/search/src/Plugin/SearchIndexingInterface.php index edae470..b2f9caa 100644 --- a/core/modules/search/src/Plugin/SearchIndexingInterface.php +++ b/core/modules/search/src/Plugin/SearchIndexingInterface.php @@ -8,12 +8,12 @@ namespace Drupal\search\Plugin; /** - * Defines an optional interface for SearchPlugin objects using the index. + * Defines an optional interface for SearchPlugin objects using an index. * * Plugins implementing this interface will have these methods invoked during * search_cron() and via the search module administration form. Plugins not - * implementing this interface are assumed to use alternate mechanisms for - * indexing the data used to provide search results. + * implementing this interface are assumed to be using their own methods for + * searching, not involving separate index tables. * * Multiple search pages can be created for each search plugin, so you will need * to choose whether these search pages should share an index (in which case @@ -45,9 +45,9 @@ public function updateIndex(); * Clears the search index for this plugin. * * When a request is made to clear all items from the search index related to - * this plugin, this method will be called. It should call - * search_index_clear($type) to remove indexed items from the search database, - * and do anything else necessary for plugin-specific indexing bookkeeping. + * this plugin, this method will be called. If this plugin uses the Core + * search index, this method can call search_index_clear($type) to remove + * indexed items from the search database. * * @see search_index_clear() */ @@ -57,13 +57,13 @@ public function searchIndexClear(); * Marks the search index for reindexing for this plugin. * * When a request is made to mark all items from the search index related to - * this plugin for reindexing, this method will be called. It should call - * search_mark_for_reindex($type) to mark the items in the search database, - * and do anything else necessary for plugin-specific indexing bookkeeping. + * this plugin for reindexing, this method will be called. If this plugin uses + * the Core search index, this method can call search_mark_for_reindex($type) + * to mark the items in the search database for reindexing. * * @see search_mark_for_reindex() */ - public function searchMarkForReindex(); + public function markForReindex(); /** * Reports the status of indexing. diff --git a/core/modules/search/src/SearchPageListBuilder.php b/core/modules/search/src/SearchPageListBuilder.php index 67cb7ee..843b64e 100644 --- a/core/modules/search/src/SearchPageListBuilder.php +++ b/core/modules/search/src/SearchPageListBuilder.php @@ -207,11 +207,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Indexing settings: $form['indexing_settings'] = array( '#type' => 'details', - '#title' => $this->t('Indexing settings'), + '#title' => $this->t('Indexing settings for default index'), '#open' => TRUE, ); $form['indexing_settings']['info'] = array( - '#markup' => $this->t('
Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.
The default settings should be appropriate for the majority of sites.
') + '#markup' => $this->t("The settings below are for search pages that use the default search index. Changing these settings will cause the default search index to be rebuilt to reflect the new settings. Searching will continue to work, based on the existing index, but new content won't be indexed until all existing content has been re-indexed.
The default settings should be appropriate for the majority of sites.
") ); $form['indexing_settings']['minimum_word_size'] = array( '#type' => 'number', @@ -329,11 +329,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $search_settings = $this->configFactory->get('search.settings'); - // If these settings change, the index needs to be rebuilt. + // If these settings change, the Core 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')); - drupal_set_message($this->t('The index will be rebuilt.')); + // Specifically mark items in the Core index for reindexing, since + // these settings are used in the search_index() function. + drupal_set_message($this->t('The default search index will be rebuilt.')); search_mark_for_reindex(); } diff --git a/core/modules/search/src/SearchPageRepositoryInterface.php b/core/modules/search/src/SearchPageRepositoryInterface.php index b75202f..7a4a40a 100644 --- a/core/modules/search/src/SearchPageRepositoryInterface.php +++ b/core/modules/search/src/SearchPageRepositoryInterface.php @@ -29,7 +29,7 @@ public function getActiveSearchPages(); public function isSearchActive(); /** - * Returns all indexable search page entities. + * Returns all active, indexable search page entities. * * @return \Drupal\search\SearchPageInterface[] * An array of indexable search page entities. diff --git a/core/modules/search/src/Tests/SearchMultilingualEntityTest.php b/core/modules/search/src/Tests/SearchMultilingualEntityTest.php index 6fb9223..df7f9e2 100644 --- a/core/modules/search/src/Tests/SearchMultilingualEntityTest.php +++ b/core/modules/search/src/Tests/SearchMultilingualEntityTest.php @@ -49,6 +49,7 @@ protected function setUp() { // Check indexing counts before adding any nodes. $this->assertIndexCounts(0, 0, 'before adding nodes'); + $this->assertDatabaseCounts(0, 0, 'before adding nodes'); // Add two new languages. $language = new Language(array( @@ -124,6 +125,7 @@ protected function setUp() { // Verify that we have 8 nodes left to do. $this->assertIndexCounts(8, 8, 'before updating the search index'); + $this->assertDatabaseCounts(0, 0, 'before updating the search index'); } /** @@ -143,6 +145,7 @@ function testMultilingualSearch() { // function manually is needed to finish the indexing process. search_update_totals(); $this->assertIndexCounts(6, 8, 'after updating partially'); + $this->assertDatabaseCounts(2, 0, 'after updating partially'); // Now index the rest of the nodes. // Make sure index throttle is high enough, via the UI. @@ -154,6 +157,15 @@ function testMultilingualSearch() { $this->plugin->updateIndex(); search_update_totals(); $this->assertIndexCounts(0, 8, 'after updating fully'); + $this->assertDatabaseCounts(8, 0, 'after updating fully'); + + // Click the reindex button on the admin page, verify counts, and reindex. + $this->drupalPostForm('admin/config/search/pages', array(), t('Re-index site')); + $this->drupalPostForm(NULL, array(), t('Re-index site')); + $this->assertIndexCounts(8, 8, 'after reindex'); + $this->assertDatabaseCounts(8, 0, 'after reindex'); + $this->plugin->updateIndex(); + search_update_totals(); // Test search results. @@ -244,16 +256,16 @@ function testMultilingualSearch() { $this->assertDatabaseCounts(8, 1, 'before clear'); search_index_clear('node_search', $this->searchable_nodes[0]->id(), 'hu'); $this->assertDatabaseCounts(8, 1, 'after clear with wrong language'); - // Correct language. + // Clear using correct language. search_index_clear('node_search', $this->searchable_nodes[0]->id(), 'en'); $this->assertDatabaseCounts(7, 1, 'after clear with right language'); // Don't specify language. search_index_clear('node_search', $this->searchable_nodes[1]->id()); $this->assertDatabaseCounts(6, 1, 'unspecified language clear'); - // Everything in 'foo'. + // Clear everything in 'foo'. search_index_clear('foo'); $this->assertDatabaseCounts(6, 0, 'other index clear'); - // Everything. + // Clear everything. search_index_clear(); $this->assertDatabaseCounts(0, 0, 'complete clear'); }