I am using Solr 8.2.2.
Given the documents in the Solr index. If we have a coordinate_rpt where coordinates are stored and if we pass the below query in the Raw Query Parameters of Solr query dashboard then it sorts the result based on the distance.
sfield=coordinate_rpt&pt=39.768403,-86.15806&sort=geodist() asc
sfield=coordinate_rpt => coordinate_rpt stores a single coordinate in an index and this field as per this query is considered to evaluate the distance
pt=39.768403,-86.15806 => pt value is the current location coordinates
sort=geodist() asc => geodist() is SOLR function query. This function must be using sfield and pt values to evaluate the distance for the corresponding document and sort accordingly.
Requirement: e.g. Consider manager and location entities, so I have documents for locations and managers. One manager can have multiple locations so I have multiple locations' coordinates for any given Manager document. Now I want to sort the managers' list based on the nearest locations.
If a manager had only one location then an inbuilt geodist() is enough. No customization is needed here.
One way I can fetch all the managers in memory of server-side application (be it asp.net MVC), fetch all the locations, evaluate the distance for each location of a manager and set up the lowest distance at the manager level, then sort the manager list by distance. Moreover, I have paginations so have to slice the result based on the page number requested. But all this happens in memory and hits the performance.
Hope I explained the issue. If any queries please comment. If any suggestions or workaround or solutions feel free to comment or answer. Thanks in advance.