Don't index certain content types I only want to have certain content types indexed, for the default Drupal 7 search. And I would like to do this without installing any other modules.

I would like to do this by hooking into the query (using hook_query_alter) that grabs all the nodes from the search_dataset. This query is found in the node_update_index function (node.module):

$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 &lt;&gt; 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(), array('target' =&gt; 'slave'));


The problem is I never get the ability to alter this query in the hook, my code is as following:

function mymodule_query_alter(&amp;$query) {
  var_dump((string)$query);
}


At some point it should print the db_query_range query. I've also tried printing my debugging to a file so I could catch those queries running ajax time.

Any ideas on what I might be doing wrong?
You can only modify SQL queries that are tagged, which this one is not. Therefore you cannot use HOOK_query_alter() to do what you are trying to accomplish.

This is hacky, but the easiest way to do this might be to implement hook_module_implements_alter() and prevent the Node module's hook_update_index() implementation from firing. You can then copy the node_update_index() function to your custom module, obviously replacing "node" in the function name with the name of your custom module, and modifying only the query to exclude whatever node types you want.

/**
 * Implements hook_module_implements_alter().
 */
function mymodule_module_implements_alter(&amp;$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( /* Your custom query here */ );

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