commit c53e9b209c523e521e3ff93a0557821e8ed52c2b
Author: Kozma Adrian <akozma@pitechplus.com>
Date:   Wed Mar 29 14:23:36 2017 +0300

    Search Api reference.

diff --git a/search_api.views.inc b/search_api.views.inc
index 43c4168..663e375 100644
--- a/search_api.views.inc
+++ b/search_api.views.inc
@@ -83,6 +83,9 @@ function search_api_views_data() {
           if (isset($field_definition['field'])) {
             $field_definition['field']['title'] = t('@field (indexed field)', array('@field' => $field_label));
           }
+          if (isset($field_definition['filter']) && isset($field_handler['entity_type'])) {
+            $field_definition['filter']['entity_type'] = $field_handler['entity_type'];
+          }
           $table[$field_alias] = $field_definition;
         }
       }
@@ -335,6 +338,18 @@ function _search_api_views_handler_mapping() {
           'id' => 'search_api',
         ),
       ),
+      'entity' => array(
+        'argument' => array(
+          'id' => 'search_api',
+          'filter' => 'intval',
+        ),
+        'filter' => array(
+          'id' => 'search_api_reference',
+        ),
+        'sort' => array(
+          'id' => 'search_api',
+        ),
+      ),
     );
 
     $alter_id = 'search_api_views_handler_mapping';
diff --git a/src/Plugin/views/filter/SearchApiReference.php b/src/Plugin/views/filter/SearchApiReference.php
new file mode 100644
index 0000000..5444ac5
--- /dev/null
+++ b/src/Plugin/views/filter/SearchApiReference.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Drupal\search_api\Plugin\views\filter;
+
+use Drupal\Core\Entity\EntityFieldManagerInterface;
+use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Cache\UncacheableDependencyTrait;
+use Drupal\views\Plugin\views\filter\EntityReference;
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
+use Drupal\views\ViewExecutable;
+
+/**
+ * Defines a filter for filtering on taxonomy term references.
+ *
+ * Based on \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid.
+ *
+ * @ingroup views_filter_handlers
+ *
+ * @ViewsFilter("search_api_reference")
+ */
+class SearchApiReference extends EntityReference {
+
+  use UncacheableDependencyTrait;
+  use SearchApiFilterTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, SelectionPluginManagerInterface $selection_plugin_manager, EntityTypeManagerInterface $entityTypeManager, EntityFieldManagerInterface $entityFieldManager) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition, $selection_plugin_manager, $entityTypeManager, $entityFieldManager);
+
+    if (!$this->value) {
+      $this->value = ["All"];
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
+    if (empty($this->definition['field_name'])) {
+      $this->view = $view;
+      $index = $this->getIndex();
+      $fields = $index->getFields();
+      if (isset($fields[$options['field']])) {
+        // The search index field name may differ from the entity field name.
+        // The entity field name is needed here.
+        $this->definition['field_name'] = $fields[$options['field']]->getPropertyPath();
+      }
+    }
+
+    parent::init($view, $display, $options);
+  }
+
+}
