Views 'Search terms' exposed filter not working as expected I have a view that displays a list of people. I want to allow the list to be filtered by its search terms, so I've added a 'Search terms' exposed filter. I'm using hook_form_alter() to override this exposed filter so the user can select from a list of countries, so they can "Search by country". This just passes a country name in as the exposed filter value. I've added a second 'Search terms' exposed filter so a user can further filter by keyword.

This doesn't seem to work as expected. When I choose 'Australia' from the first filter, I get 39 results, which is correct. When I then enter 'Astronomy' into the second filter, I get no results. I expected to get back 1 result, a user whose node contains both 'Australia' and 'Astronomy'. If I leave one filter blank and enter 'Australia Astronomy' into the other, I get the correct user result.

Is there a way to make this work the way I want to? The first exposed filter has to be filtering on a node's indexed content (find country mentioned anywhere in the node), so I can't filter on a single field here. Thanks in advance!
The mistake comes from the WHERE conditions : 

AND(( (search_index.type = 'node') AND( (search_index.word = 'australia') ))AND( (search_index.type = 'node') AND( (search_index.word = 'astronomy') ))))


This will always return empty result ! Not convinced?  simply try

    SELECT * FROM `search_index` WHERE `word` = 'Australia' AND `word` = 'Astronomy'


So you'll need a subquery here : for the sake of example, let's say :

SELECT node.title AS node_title, node.nid AS nid
FROM node 
LEFT JOIN search_index ON node.nid = search_index.sid
WHERE node.status = '1' 
AND  search_index.word = 'Astronomy'
AND sid IN ( 
    SELECT sid FROM `search_index` WHERE `word` = 'Australia' 
)
LIMIT 0 , 30


Now to get it I suggest that you implement hook_views_query_alter(&amp;$view, &amp;$query). First, call Views API :

/**
 * Implementation of hook_views_api().
 */
function YOUR_MODULE_views_api() {
  return array(
    'api' =&gt; 3, //Views 3
    'path' =&gt; drupal_get_path('module', 'YOUR_MODULE'),
  );
}


And then the tricky part

function YOUR_MODULE_views_query_alter(&amp;$view, &amp;$query) {
  if($view-&gt;name == 'YOUR_VIEW' &amp;&amp; (count($view-&gt;YOUR_EXPOSED_FIELD) &gt; 1 ) )  {
    dpm($view); //OR dpm($query); 
    //alter your query here ; you'll have to debug and tune the following lines
    //short one
    $query-&gt;where ... = ...
    //alternative one
    foreach($query-&gt;where as &amp;$condition_group) {
      foreach($condition_group['conditions'] as &amp;$condition) {
        //not sure from here, use `dpm ()` on your own objects            
        if($condition['field'] == 'search_index.word') {
          $condition = array(
            'field' =&gt; 'search_index.sid',
            'value' =&gt; db_query('SELECT sid FROM `search_index` WHERE `word` = '.$view-&gt;YOUR_EXPOSED_FIELD),
            'operator' =&gt; 'IN',
          );
        }
      }
    }
  }
}



  This hook should be placed in MODULENAME.views.inc and it will be
  auto-loaded. MODULENAME.views.inc must be in the directory specified
  by the 'path' key returned by MODULENAME_views_api(), or the same
  directory as the .module file, if 'path' is unspecified.


EDIT : as per Vincent, used add_where_expression for the subquery and unset the original part of the query related to that search

$query-&gt;add_where_expression('3', "sid IN (SELECT sid FROM search_index WHERE search_index.word = '{$search_value}')");
//sthing like
unset($query-&gt;where[1]['conditions'][0]);