4

I have a custom content type that I simply want to not be indexed by the Drupal search engine. Yes, I can hide it from the search results, but there are hundreds of thousands of these nodes and rebuilding the index takes days. After much searching and trial/error, I came across this solution from ChrisPliakus.

You can see my query below in the update_index hook, where I exclude MY_CONTENT_TYPE from the query. I've tested the query manually and it seems to show nodes other than the one I want to ignore, which I think is the goal there.

However, when I run drush cron --verbose, I still see those nodes getting indexed :(


/**
 * Implements hook_module_implements_alter().
 */
function MYMODULE_module_implements_alter(&$implementations, $hook) {
  if ('update_index' == $hook) {
    unset($implementations['node']);
  }
}

/**
 * Implements hook_update_index().
 *
 * @see node_update_index().
 */
function MYMODULE_update_index() {
  $limit = (int) variable_get('search_cron_limit', 100);

  $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE (d.sid IS NULL OR d.reindex <> 0) AND n.type != 'MY_CONTENT_TYPE' ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(), array('target' => 'slave'));

  foreach ($result as $node) {
    _node_index_node($node);
  }
}

Any ideas? Thanks in advance!

  • From what I'm reading, I also need to implement hook_search_info, though I'm lost a bit at this point. – Roderick Samuels Oct 24 '12 at 20:09
0

Rather than coding a custom solution, I would use a supported module. The answer I believe will help you: Restrict Drupal Search to few content types

So for Drupal 7 you can use Custom Search, Search Config or Search API Exclude if you are using Search API. For Drupal 8 you can use Search Exclude.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.