Using hook_query_TAG_alter to add 'OR' queries to EntityFieldQuery I need to use the OR operator on an EntityFieldQuery which I understand can only be accomplished via addTag and hook_query_TAG_alter.

My query at present:

$query = new EntityFieldQuery();
$query-&gt;propertyOrderBy('created', 'DESC');
$query-&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', 'news')
    -&gt;propertyCondition('status', 1)
    -&gt;fieldCondition('field_pub_year', 'value', $year, '=');
if(isset($_GET['country_id'])){
    $country = $_GET['country_id'];
    $query-&gt;fieldCondition('field_related_country', 'target_id', $country, '=');
}
if(isset($keywords)){
    $query-&gt;addTag('search');
}
$result = $query-&gt;execute();


Without much more than a rudimentary knowledge of Drupal, I would expect that the following function, inserted into my template, might work:

function hook_query_search_alter(QueryAlterableInterface $query){
    $or = db_or()
      -&gt;fieldCondition('title', 'value','%'. $keywords .'%', 'LIKE')
      -&gt;fieldCondition('body', 'value','%'. $keywords .'%', 'LIKE');
    $query-&gt;condition($or);
}


Yet, it seems to do nothing...

I'm having equal luck googling this problem. Appreciate any suggestions.  Thanks.

Update:

I moved the alter function into a module and re-wrote it to look like:

function modulename_query_search_alter(QueryAlterableInterface $query){
    $terms = $query-&gt;getMetaData('terms');
    $words = "%".$terms."%";
    $or = db_or()-&gt;condition('body', $words, 'LIKE')-&gt;condition('title', $words, 'LIKE');
    $query-&gt;condition($or);
}


but I now get an unknown column body error.  Removing that condition works correctly and results are filtered by title field. Not sure what the deal is with that...
Solution to using 'OR' queries with EntityFieldQuery:

The query, note the addTag() and addMetaData():

$query = new EntityFieldQuery();
$query-&gt;propertyOrderBy('created', 'DESC');
$query-&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', 'news')
    -&gt;propertyCondition('status', 1);
if(isset($keywords)){
    $query-&gt;addTag('search');
    $query-&gt;addMetaData('terms', $keywords);
}
$result = $query-&gt;execute();
if(isset($result['node'])){
    $nids = array_keys($result['node']);
} else {
    $nids = array();
}
$news = node_load_multiple($nids);


Then, within a module or something, the hook_query_TAG_alter looks like:

function MODULENAME_query_TAGNAME_alter(QueryAlterableInterface $query){
    $terms = $query-&gt;getMetaData('terms');
    $words = "%".$terms."%";
    $query-&gt;leftJoin('field_data_field_subtitle', 's', 'node.nid = s.entity_id');
    $or = db_or()-&gt;condition('s.field_subtitle_value', $words, 'LIKE')-&gt;condition('title', $words, 'LIKE');
    $query-&gt;leftJoin('field_data_body', 'b', 'node.nid = b.entity_id');
    $or-&gt;condition('b.body_value', $words, 'LIKE');
    $query-&gt;condition($or);
}


Above example shows how to join custom field tables and query them using 'OR' along with title and body fields.