I'm using search_api/search_api_solr, and would like to be able to exclude certain nodes from being indexed by Solr at all. In looking at search_api.api.php, I see this text:

Please be aware that generally preventing the indexing of certain items is deprecated. This is better done with data alterations, which can easily be configured and only added to indexes where this behaviour is wanted. If your module will use this hook to reject certain items from indexing, please document this clearly to avoid confusion.

I'm just getting into the whole entity API, so it's not so "easy" for me to do this. I'm thinking that he's referring to hook_entity_property_info_alter(), and I've used that to add a property to an entity so it is available as a facet and field available in search results. However, I'm not seeing how to alter the entity so that I can control whether it is indexed by search_api or not. Can someone point me in the right direction?



When he says "better done with data alterations" he is referring to the "Data Alterations" fieldset / section in the "Workflow" tab for each index in the UI and that is accessible in code through hook_search_api_alter_callback_info().

You can see a patch that uses this (it doesn't use the hook but the original function because it is being added to the actual search_api module but you get the idea) to not index unpublished nodes: http://drupal.org/node/1507882

I think his audience for this comment is other contributed module makers. You can imagine it would be extremely confusing for a user if certain items didn't get indexed because a module they turned on used that hook.

If you are trying to exclude nodes from being indexed (be aware that you can use the "Node Access" data alteration which will keep unpublished nodes from being returned for searches for users who don't have content editing access) you can use that hook checking for the node ids and unsetting them as in the example function.

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.