Option to eliminate entries from search_index and search_dataset

Created on 23 April 2013, over 11 years ago
Updated 18 April 2024, 8 months ago

In sites I've deployed recently, I use search_config to set up some basic search restrictions.
However, some of those sites still have exploding search_dataset and search_index table size, especially if i have thousands of users and node_profile or profile2.

I've implemented the following hook_cron to reduce the size of these tables, and prevent any accidental exposing of restricted content types:

function MYMODULE_cron() {
  // More search workaround'ing.
  $types = variable_get('search_config_disable_index_type', array());
  if (empty($types)) {
    return;
  }
  $ph = db_placeholders($types, 'varchar');
  // Search indexing works by combing search_dataset for missing sids, or sids
  // marked for reindexing,so we can't simply delete the rows. Set the 
  // search_dataset data to empty string, so that the search module won't try to
  // index the content.
  db_query("INSERT INTO search_dataset 
      (sid, type, data, reindex)
      SELECT nid, 'node', '', 0 FROM node WHERE node.type IN ($ph)
      ON DUPLICATE KEY UPDATE reindex = 0, data = ''", $types);
  // Entry from search_index can be deleted.
  db_query("DELETE from search_index where sid in 
(SELECT nid FROM node WHERE node.type IN ($ph))", $types);
}

This has reduced the size of search_dataset significantly, and in one case, eliminated millions of rows from search_index.
Would other folks find this useful in search_config module?
If so I will write a patch that includes this option as a checkbox on the search config admin page.

✨ Feature request
Status

Closed: outdated

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine AstonVictor

    I'm closing it because the issue was created a long time ago without any further steps.

    if you still need it then raise a new one.
    thanks

Production build 0.71.5 2024