Solarium Query Example in Drupal 8

When using Search API Solr in Drupal 8, I needed to run some more in-depth queries than were available via the Search API Query, but couldn't find any examples online of how to run a Solarium query directly. After digging around in the module, I found some examples in the SearchApiSolrBackend. If anyone else is looking for the same, here's how to run a basic Solarium query:

use Drupal\search_api\Entity\Index;
use Solarium\QueryType\Select\Query\Query;
use Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend;

/** @var Index $index */
$index = Index::load('images');

/** @var SearchApiSolrBackend $backend */
$backend = $index->getServerInstance()->getBackend();

$connector = $backend->getSolrConnector();

$solarium_query = $connector->getSelectQuery();
$solarium_query->createFilterQuery('archive_id')->setQuery('"id-12345"');
$solarium_query->addSort('sequence_id', Query::SORT_ASC);
$solarium_query->setRows(1);

$result = $connector->execute($solarium_query);

// The total number of documents found by Solr.
$found = $result->getNumFound();

// The total number of documents returned from the query.
$count = $result->count();

// Check the Solr response status (not the HTTP status).
// Can't find much documentation for this apart from https://lucene.472066.n3.nabble.com/Response-status-td490876.html#a3703172.
$status = $result->getStatus();

// An array of documents. Can also iterate directly on $result.
$documents = $result->getDocuments();

For more information on the query syntax, see the Solarium documentation.