Reindexing node types in Drupal 6

I’ve been reworking search functionality on a fairly large Drupal 6 installation.  Until recently, every time I changed what the search indexed for a custom module, I just went to /admin/settings/search and clicked ‘Re-index site’.

This works on smaller websites, but when a website grows to have thousands and thousands of searchable nodes, re-running the cron job until everything is indexed becomes very tedious and time consuming.

Your site’s search functionality will be down until everything is reindexed.  Not good.

The good news is there’s a way to reindex specific node types!  When you’re done modifying the ‘update index’ action of the hook_nodeapi() in your custom module, just log into mysql and run this to flag nodes to be reindexed (replacing ‘node-type-goes-here’ with the node type you’d like to reindex):

UPDATE search_dataset sd
INNER JOIN node n ON sd.sid = n.nid
SET sd.reindex = 1
WHERE n.type = ‘node-type-goes-here’

Then, run your cron job to reindex the nodes.

It’s that easy!

Comments

    jrockowitz |

    I know this is old post but thanks for saving me 15 minutes.