diff --git a/src/Plugin/views/query/SearchApiQuery.php b/src/Plugin/views/query/SearchApiQuery.php
index 024367d5..47141f5d 100644
--- a/src/Plugin/views/query/SearchApiQuery.php
+++ b/src/Plugin/views/query/SearchApiQuery.php
@@ -385,6 +385,28 @@ public function getEntityTypes($return_bool = FALSE) {
     return $return_bool ? (bool) $types : $types;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function query($get_count = FALSE) {
+    // Try to determine whether build() has been called yet.
+    if (empty($this->view->build_info['query'])) {
+      // If not, call it in case we at least have a view set. If we don't, we
+      // can't really do anything.
+      if (!$this->view) {
+        return NULL;
+      }
+      $this->build($this->view);
+    }
+
+    $query = clone $this->query;
+    // A count query doesn't need to return any results.
+    if ($get_count) {
+      $query->range(0, 0);
+    }
+    return $query;
+  }
+
   /**
    * {@inheritdoc}
    */
