How can I add a condition to default search module?
I want to add a checkbox field called "Allow to search" to nodes, and unchecked items will not show in search results.
Extending Drupal 7 search seems to be my solution, but I can't make it work; hook_search_execute()
is not executed.
Can you explain why this happens?
You need to first select your module on admin/config/search/settings, and possibly unselect the Node module in the "Active search modules." If your module is not selected there, your hook will not invoked.
As for the reason why one hook is invoked, and one is not invoke, the code executed by search_get_info() (the function called from search_menu() to build the search menu) first invokes every implementation of
hook_search_info()
, and then it checks for which modules the search integration has been enabled. Since your module doesn't have the search integration enabled,hook_search_execute()
for your module will never be invoked.