diff --git a/src/Query/Query.php b/src/Query/Query.php
--- a/src/Query/Query.php
+++ b/src/Query/Query.php
@@ -464,6 +464,28 @@ public function sort($field, $order = self::SORT_ASC) {
     return $this;
   }

+  /**
+   * {@inheritdoc}
+   */
+  public function scriptSort($field, $order = self::SORT_ASC, $scores = []) {
+    $order = strtoupper(trim($order));
+    $order = $order == self::SORT_DESC ? self::SORT_DESC : self::SORT_ASC;
+    if (!isset($this->sorts[$field])) {
+      $scriptName = 'script_' . $field;
+      $script = [
+        'script' => [
+        'lang' => 'painless',
+          'inline' => "if(params.scores.containsKey(doc['$field'].value)) {return params.scores[doc['$field'].value];} return 10000;",
+          'params' => ['scores' => $scores],
+        ],
+        'type' => 'number',
+        'order' => strtolower($order),
+      ];
+      $this->sorts['_script'] = $script;
+    }
+    return $this;
+  }
+
   /**
    * {@inheritdoc}
    */
diff --git a/src/Query/QueryInterface.php b/src/Query/QueryInterface.php
--- a/src/Query/QueryInterface.php
+++ b/src/Query/QueryInterface.php
@@ -215,6 +215,32 @@ public function setFulltextFields(array $fields = NULL);
    */
   public function sort($field, $order = self::SORT_ASC);

+  /**
+   * Adds a sort directive to this search query.
+   *
+   * If no sort is manually set, the results will be sorted descending by
+   * relevance.
+   *
+   * @param string $field
+   *   The ID of the field to sort by. In addition to all indexed fields on the
+   *   index, the following special field IDs may be used:
+   *   - search_api_relevance: Sort by relevance.
+   *   - search_api_datasource: Sort by datasource.
+   *   - search_api_language: Sort by language.
+   *   - search_api_id: Sort by item ID.
+   * @param string $order
+   *   The order to sort items in – one of the SORT_* constants.
+   *
+   * @param array $scores
+   *  The scores of items that should be considered when determining order.
+   *
+   * @return $this
+   *
+   * @see \Drupal\search_api\Query\QueryInterface::SORT_ASC
+   * @see \Drupal\search_api\Query\QueryInterface::SORT_DESC
+   */
+  public function scriptSort($field, $order = self::SORT_ASC, $scores = []);
+
   /**
    * Adds a range of results to return.
    *
