In a Sorl index based view, I want to sort the results on the distance to the given location. The view uses an exposed filter. The field is of Geofield type. The two Views field types ("{Field name} (distance)" and "{Field name} (indexed field) - distance"), both give the same error. The error only occurs when the Location filter input empty.

An error occurred while trying to search with Solr: {"error":{"metadata":["error-class","org.apache.solr.common.SolrException","root-error-class","org.apache.solr.common.SolrException"],"msg":"Sorting not supported on LatLonType locs_field_lat_lon__distance","code":400}} .

The Readme does not provide addition info.

Comments

Sutharsan created an issue. See original summary.

dbjpanda’s picture

StatusFileSize
new18.48 KB

Hi @Sutharsan I have just compiled all the patches into one patch. Its working fine for me. I can sort as well. You can have a try.

If you want to apply the patches individually then try these order.
1 - https://www.drupal.org/project/search_api_location/issues/2878726#commen...
2- https://www.drupal.org/project/search_api_location/issues/2905431#commen...
3- https://www.drupal.org/project/search_api_location/issues/2913666
4- https://www.drupal.org/project/search_api_location/issues/2954999

dbjpanda’s picture

Title: How to sort on calculated distance » How to sort on calculated distance
Status: Active » Closed (cannot reproduce)
strykaizer’s picture

Status: Closed (cannot reproduce) » Active

I'm experiencing the same issue.

Once I add an extra sort on my search api views page, on distance, I have no results anymore.

I'm using dev version (tried with last beta too).

sutharsan’s picture

Category: Support request » Bug report
Issue summary: View changes

The error only occurs when the search input is empty.
Changing category to 'bug report'

The patches 2905431 and 2954999 in #2 do not solve the error. (2878726 already comitted, 2913666 not tested)

sutharsan’s picture

Title: How to sort on calculated distance » Error when sorting on calculated distance without given location
mollux’s picture

Status: Active » Needs review
StatusFileSize
new4.06 KB

I was able to reproduce this, and it is an interesting bug.

When adding sorting on distance, there is no check if there is actually any spatial information available in the query.
This is the case with an empty exposed spatial filter, or when no spatial filter is added.

I Fixed this by overriding the sort plugin for the distance field, so sorting on distance can be skipped when no spatial info is available.
I also removed the filter on the distance pseudo field, as distance filtering is what is done by the spatial filter.

There is 1 caveat, I currently have to guess the name of the distance field, as the backend doesn't provide that info.

I also want to add a test for this, but still figuring out the bast approach for this.

@stryKaizer and @Sutharsan, can you try the patch and give some feedback?
No additional patches are necessary with the latest dev release.

strykaizer’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #7 fixes empty distance search. Thx!

  • mollux authored 17da652 on 8.x-1.x
    Issue #2954279 by dbjpanda, mollux: Error when sorting on calculated...
mollux’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the feedback.
Committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.