Approach to custom advanced search box I have a custom search form, made with Drupal Form API. It uses ajax, autocomplete, and some other properties defined in the built $form.

I use the data sent from the form to feed a views_embed_view call, and in the View I have defined some contextual filters, for each and every of the input boxes.

The problem is that Contextual filters do not apparently support the operator LIKE for several word or partial word matches, so the search is very restricted. Even putting Search field instead of Content field does not solve the problem completely.

If I use Exposed filters instead of Contextual filters, I don't know how to modify the input boxes to get all the functionality I already have. Maybe with hook_form_alter, but even so I do not know what to do with the sent data (it needs further PHP processing, this is why it was so convenient with Contextual filters).

I also found this piece of code I had already used (but forgotten), but I don't find the solution elegant (even if it works - it is taken from a different Drupal Answers question and adapted. It modifies the Contextual filter query and includes the LIKE operator):

function mymodule_views_query_alter(&amp;$view, &amp;$query) {
if( $view-&gt;name == "products_list" ){
    foreach($query-&gt;where as $key =&gt; $val) {
        $field = $val['conditions'][0]['field'];
        $operator = $val['conditions'][0]['operator'];
        $value = $val['conditions'][0]['value'];
        if(( $field == 'field_data_field_field_rf_producto.field_field_producto_value' || $field == "field_data_field_descripcion_producto.field_descripcion_producto_value") &amp;&amp; $operator == '=') {
            $query-&gt;where[$key]['conditions'][0]['operator'] = 'LIKE';
            $query-&gt;where[$key]['conditions'][0]['value'] = '%' . $value . '%';
        } // if
    } // foreach
  } // if
} // function
You can programmatically change the filter configuration before executing the view:

$view_name    = 'my_view_name';
$display_name = 'my_display_name';
$handler_name = 'title';
$terms        = array('foo', 'bar');

$view = views_get_view($view_name);
$view-&gt;set_display($display_name);

$handler = $view-&gt;display_handler-&gt;get_handler('filter', $handler_name);
$handler-&gt;value = implode(' ', $terms);

$output = $view-&gt;preview();


This will work even without exposing the filter.