Search API Views Query Alter Example

/** 
 * Implements hook_search_api_views_query_alter().
 */
function cga_publications_search_api_views_query_alter(view &$view, SearchApiViewsQuery &$query) {
  if (!empty($view->exposed_raw_input['field_date'])) {
    $or = $query->createFilter('AND');                           
    $start = new DateTime($view->exposed_raw_input['field_date'] . "-01-01");                                                                     
    $start_date = $start->format('Y-m-d H:i:s');                                                                                                  
    $end = new DateTime($view->exposed_raw_input['field_date'] . '-12-31');                                                                       
    $end_date = $end->format('Y-m-d H:i:s');                                                                                                      
    $or->condition('field_date', $start_date, '>=');                                                                                              
    $or->condition('field_date', $end_date, '<=');                                                                                                
    $query->filter($or);                                                                                                                          
  }                                                                                                                                               
}