diff --git a/views/entityreference_filter_view_result.inc b/views/entityreference_filter_view_result.inc
index 7c2fa63..49bc247 100644
--- a/views/entityreference_filter_view_result.inc
+++ b/views/entityreference_filter_view_result.inc
@@ -191,7 +191,73 @@ class entityreference_filter_view_result extends views_handler_filter_in_operato
       }
     }
 
-    parent::query();
+    if (substr($this->view->base_table, 0, 17) == 'search_api_index_') {
+      $this->_query_for_search_api_index();
+    }
+    else {
+      parent::query();
+    }
+  }
+
+  /**
+   * Add this filter to the query.
+   *
+   * Copy and paste from:
+   *   @see search_api/contrib/search_api_views/includes/handler_filter_options.inc::query()
+   */
+  protected function _query_for_search_api_index() {
+    if ($this->operator === 'empty') {
+      $this->query->condition($this->real_field, NULL, '=', $this->options['group']);
+      return;
+    }
+    if ($this->operator === 'not empty') {
+      $this->query->condition($this->real_field, NULL, '<>', $this->options['group']);
+      return;
+    }
+
+    // Extract the value.
+    while (is_array($this->value) && count($this->value) == 1) {
+      $this->value = reset($this->value);
+    }
+
+    // Determine operator and conjunction. The defaults are already right for
+    // "all of".
+    $operator = '=';
+    $conjunction = 'AND';
+    switch ($this->operator) {
+      case '=':
+      case 'in': // Changed from SearchAPI: "in" translated to "=" operator
+        $conjunction = 'OR';
+        break;
+
+      case '<>':
+      case 'not in': // Changed from SearchAPI: "not in" translated to "<>" operator
+        $operator = '<>';
+        break;
+    }
+
+    // If the value is an empty array, we either want no filter at all (for
+    // "is none of"), or want to find only items with no value for the field.
+    if ($this->value === array()) {
+      if ($operator != '<>') {
+        $this->query->condition($this->real_field, NULL, '=', $this->options['group']);
+      }
+      return;
+    }
+
+    if (is_scalar($this->value) && $this->value !== '') {
+      $this->query->condition($this->real_field, $this->value, $operator, $this->options['group']);
+    }
+    elseif ($this->value) {
+      $filter = $this->query->createFilter($conjunction);
+      // $filter will be NULL if there were errors in the query.
+      if ($filter) {
+        foreach ($this->value as $v) {
+          $filter->condition($this->real_field, $v, $operator);
+        }
+        $this->query->filter($filter, $this->options['group']);
+      }
+    }
   }
 
   function get_configured_views_result() {
