3

If a content type has additional text fields, search core automatically indexes them because search core extracts all text from the result of node_view()

I can easily add extra index data via MODULE_node_update_index( $node ). This particular hook argument, $node, is passed by value and not by reference which means I can't unset certain items.

I hook into node_view, and alter it there but I don't want to change the output of the node normally, only when it's being indexed.

11

Goto the Manage Display page for each content type (eg, admin/structure/types/manage/page/display).

Click on the tab for Custom Display Settings.

You will see the view modes that your system knows about. Tick Search Index and save.

You can now configure which fields get indexed from the tab for that new display mode (eg admin/structure/types/manage/page/display/search_index)

Dump the search index from Configuration -> Search -> Search Settings ( admin/config/search/settings), and cron runs will re-index everything. Or, do a drush -y search-reindex; drush -y search-index from the command line.

Start reading from node_update_index() which is invoked from search_cron(), and you will eventually see a node_view($node, 'search_index');, which is how that display mode gets used.

  • If I do this and make no fields displayed for Search Index, will this eliminate that content type from showing up in search results? – Christia Sep 26 '17 at 10:50
  • @ChristiaNot sure, never tried that. Pretty sure the custom_search module will handle this, though. There should be one or more questions here about how to hide content types from search. – mpdonadio Sep 26 '17 at 12:33

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.