How to send a custom Solr Distance Query with SearchApi My nodes have a geofield and my search query should find all the nodes within a range.

I've managed to create a search form against my Solr Server with views. But I want to do the request by myself (having my own form and submit method). There's a solution for D7 here: How to send a custom Solr Query using Search API Solr but none of that seems to be usable with the D8 modules.

I believe there must be something like 

$result = SolrSearchService('myServer', 'myIndex')-&gt;request(['title' =&gt; 'Test']);


But I can not find anything.

The views-built search page renders a query against my Solr Server like

path=/select params={q=(phonm_rendered_item:nintendo^1+tm_title:nintendo^8)&amp;json.nl=flat&amp;pt=48.1371079,11.5753822&amp;d=50&amp;omitHeader=true&amp;fl=ss_search_api_id,ss_search_api_language,score,fts_field_geo_koordinaten__distance:geodist()&amp;start=0&amp;fq=%2Bindex_id:default_solr_index+%2Bhash:ozztjn&amp;fq={!geofilt}&amp;rows=10&amp;sfield=locs_field_geo_koordinaten&amp;wt=json} 


Apparently there are some parameters responsible for the distance calculation: 


pt=48.1371079,11.5753822 - it's where I am
d=50 - it's the max distance
field_geo_koordinaten - it's the geofield in the node
geodist() - the function ?


How can I render such a query with Search API?
Debugging around I found the solution:

$index = Index::load('default_solr_index');
/* @var \Drupal\search_api\Query\Query $query */
$query = $index-&gt;query();
$query-&gt;keys($form_state-&gt;getValue("keys"));
$location_options = (array) $query-&gt;getOption('search_api_location', []);

$location_options[] = [
      'field' =&gt; "field_geo_koordinaten",
      'lat' =&gt; 48.1371079,
      'lon' =&gt; 11.5753822,
      'radius' =&gt; 50,
    ];

$query-&gt;setOption('search_api_location', $location_options);
$results = $query-&gt;execute();


Thanks for pointing me in the right direction.