I tried to use node_search_execute() to search nodes. So far, running the function is easy. I noticed that there was a $conditions parameter from the documentation of hook_search_execute().

Is there a way to extend the search function to also search for taxonomy terms? Simple friendly pointers to guide me to do fast and complete node search are also welcomed.

  • Sorry, I'm sure it would be wonderful if there was somewhere you could go and people would just write your code for free based on a terse specification, but this isn't it :) If you have a specific question about an error or problem you're having with your own development please do ask it, but make sure you include the code you're using, error messages, generally what you've tried already. Please see the FAQ for more details. – Clive May 16 '13 at 18:12
  • It is possible to answer this question, even if it is not showing any code. It is asking if it is possible to implement a feature. I am going to answer it. – kiamlaluno May 17 '13 at 13:51
  • Thank you, kiamlaluno. Clive was correct; my original question was not clear. – user173457 May 17 '13 at 18:02

Actually, the only missing part is the form field that should allow the users to select the taxonomy terms used from the nodes they are looking for. The code used from Drupal 7 (and Drupal 8) is still looking for the corresponding values in $form_state['values'].

If you look at the code used by node_search_validate(), the form validation handler added by node_form_search_form_alter(), you will notice the following lines.

  if (isset($form_state['values']['term']) && is_array($form_state['values']['term']) && count($form_state['values']['term'])) {
    $keys = search_expression_insert($keys, 'term', implode(',', $form_state['values']['term']));

If you then look at the code used by node_search_execute(), you will notice the following lines.

  if ($query->setOption('term', 'ti.tid')) {
    $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');

Effectively, the functionality of searching those nodes that use specific taxonomy terms has not been removed; it has been hidden to the users who don't have anymore a way to tell the Node module to which taxonomy terms they are interested. This seems rather unintentional; probably the feature was supposed to be completely removed, but the submitted patch removed just the code for the user interface. I cannot find the related issue opened on Drupal.org, and I cannot say if my supposition is correct.

Until the code in node_search_execute() and node_search_validate() is not changed, all you need to do is adding the form fields in the search form, keeping in mind that the Node module is looking for $form_state['values']['term']. (In other words, the form field added for selecting the taxonomy terms should be in $form['term'].)

If, and when, that code is removed, adding that form field would not have anymore any effect.
Drupal doesn't allow a module to alter how a module integrates with the Search module. As a matter of fact, Drupal uses hook_search_info(), but no hook_search_info_alter(); if you would want to extend how searching a node is done (for example, by adding more options), you would need to alter the page callback assigned to search/node and search/node/%menu_trail. See search_menu().

Drupal 6

Drupal 7


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.