Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
any way to show the distance from the entered location point in a search and display it as a field for each view result item? maybe a field that would display 10 km or 10 miles from point?
Comment | File | Size | Author |
---|---|---|---|
#9 | 2050961-9--return_distance.patch | 3.21 KB | drunken monkey |
#9 | 2050961-9--return_distance--interdiff--do-not-test.patch | 2.48 KB | drunken monkey |
Comments
Comment #1
drunken monkeyNo, not without custom code. It's kind of hard to bring Solr to return this.
Comment #2
das-peter CreditAttribution: das-peter commentedThe attached patch provides together with #1812528: Add proximity/distance information to search results a way to add / calculate the distance to the search results.
If solr 3 is used the coordinates instead the actual distance is added to the search result. We could calculate the distance on our own with those coordinates but I think that belongs into the problem space of the location module (and it's already solved there).
Do we have somewhere a documentation how the correct implementation of
search_api_location
support has to look like?Comment #3
das-peter CreditAttribution: das-peter commentedMore speaking title.
Comment #4
das-peter CreditAttribution: das-peter commentedMore defensive code.
Comment #5
drunken monkeyThanks, great work!
As already noted in #1812528-15: Add proximity/distance information to search results, this works perfectly but I think the underlying mechanism still should/could be improved.
Yes, in the
README.txt
file of the Search API Location module.You also claim that in the inline comments, however, you seem to have forgotten to also add that. I guess there should be an
else
in the code added inextractResults()
that takes care of this.Also, I think the Solr 3 method should also work without clean identifiers – returning fields also works when they contain colons, as far as I'm aware of.
Lastly:
This means, unless I'm mistaken, that this will only work for a single location field, even though all other code would work for multiple fields as well. Why not pass the field and point in the
geodist()
function call?Comment #6
das-peter CreditAttribution: das-peter commentedHere's an updated patch that takes the new search_api_location approach in account.
The compatibility with multiple spatial infos should be better too.
Attention: Solr3 code isn't tested as I don't have an instance available atm.
Comment #7
drunken monkeyThanks for the improvements!
However, I still have a few comments which need to be addressed:
This should probably have an
if (isset($location_params['fl']))
. Or, if you are only puttingfl
into$location_params
, just use a$location_fields
variable directly.Why the
str_replace()
? I think you're only adding this if the Solr field name doesn't have any colons?Solr 3.x doesn't have field aliases, so this will be interpreted as a literal field name (e.g.,
field_location:latlon_distance:locs_field_location:latlon
), which won't be found.You should probably just add the field to
fl
and check for that later when extracting the results.Comment #8
das-peter CreditAttribution: das-peter commentedFinally back at work here :)
Thanks for the feedback.
$location_fields
$field
- no clue if that works. I don't have a solr3 instance ready to test it.Comment #9
drunken monkeyLooks great, thanks again!
Attached is a slightly revised patch. Apart from the mechanism change mentioned in #1812528-31: Add proximity/distance information to search results (using a new response key instead of a magic field), I also removed the adding of the field to
fl
for Solr 3.x: if the distance data isn't available, the Views field handler (or whatever other consumer) can just get the field value in the usual way. If the user wants it to be retrieved from Solr, they can just enable "Retrieve results data from Solr". I see no need in a special treatment for that.Comment #10
das-peter CreditAttribution: das-peter commentedOkay then let's do that. Looks good to me.
Comment #12
drunken monkeyExcellent. Committed.
Thanks again!