I only want certain nodes to be indexed. The "search config" module claims to have this capability, but it doesn't work. So, how do I either edit the node module to only index certain nodes, or better yet, impliment a module that can do this for me?
This is a long standing feature request, but it looks like it has already been pushed to at least Drupal 8 :/
You can find some workaround suggestions in the feature request discussion linked above, but the 'standard' approach used by the search config module is described here. It does not prevent the nodes from being indexed, but manipulates the search queries to ignore certain entries (e.g. node types) so that they won't show up on the search result pages.
As there is no obviously better solution at the moment (afaik), I agree with ceejayoz´ comment that you should first check why the search config module does not work for you before embarking on custom coding your own solution.
If you have to resort to editing the node module itself, node_update_index()
would be the place to start.
Here's the query that determines what needs to be indexed, from node_update_index():
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
ORDER BY d.reindex ASC, n.nid ASC
You can't prevent the indexing script from running. But you can trick that query into thinking content is already indexed by inserting dummy entries into {search_dataset}.
For example, if you're using MySQL, do this on cron:
INSERT INTO {search_dataset}
(sid, type, data, reindex)
SELECT nid, 'node', '', 0 FROM {node} WHERE node.type IN (RESTRICTED_TYPES)
ON DUPLICATE KEY UPDATE reindex = 0, data = ''
Replace "RESTRICTED_TYPES" with your list of node types, and do a similar query for each entity you want to restrict from search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With