LIKE clause not working in hook query alter I'm trying to replace the default search with a LIKE clause in Drupal 7. I tried to alter the query according to Adding an OR condition to an existing query:

function MYMODULE_query_node_access_alter(QueryAlterableInterface $query) {
  foreach ($query-&gt;getTables() as $table) {
    // LIKE for search results.
    if ($table['table'] == 'search_index') {
      // Get the query args and then the search term
      $args =&amp; $query-&gt;getArguments();
      $search = $args[':db_condition_placeholder_1'];

      // Get a reference to the existing query conditions.
      $conditions =&amp; $query-&gt;conditions();

      // Save the former conditions
      $former_conditions = $conditions;

      // Reset the condition array. It needs a default #conjunction for which AND is fine
      $conditions = array('#conjunction' =&gt; array_shift($former_conditions));

      // Replace the search condition in the query
      foreach ($former_conditions as $key =&gt; $condition) {
        if ($key != 1) {
          $query-&gt;condition($condition['field'], $condition['value'], $condition['operator']);
        }
        else {
          $query-&gt;condition('i.word', '%' . db_like($search) . '%', 'LIKE');
        }
      }
    }
  }
}


Searching with the word "declaration" displays the same results as the default drupal search, but searching with "decl" doesn't find any results.

Any ideas why my code isn't working?
Have you tried changing the hook you are using to MYMODULE_query_alter?

You are implementing hook_query_TAG_alter(), and I don't see where the Search query is tagged as such.

Per the Node API:


  This is the hook_query_alter() for queries tagged with 'node_access'.
  It adds node access checks for the user account given by the 'account'
  meta-data (or global $user if not provided), for an operation given by
  the 'op' meta-data (or 'view' if not provided; other possible values
  are 'update' and 'delete')