Order Facebook Places results by distance

爷,独闯天下 提交于 2019-12-18 14:47:01

问题


Does anyone know how to order Facebook places by distance from a search location? Note that I don't want to order results in my client app. I want the Facebook server to provide me with ordered results to facilitate pagination. I always want to append places from subsequent queries to the end of my array.

This does not seem possible using the graph API query such as:

https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000&.... because there is no way to tell Facebook to order the results. The nearest place may be last in the list of returned results.

I have been trying to replicate the above query using FQL but have a problem in that the name & description fields in the Facebook place table are not indexable. FQL such as:

SELECT 
  page_id, name, display_subtext, description, 
  distance(latitude, longitude, "37.76", "-122.427"), checkin_count 
FROM place 
WHERE ((distance(latitude, longitude, "37.76", "-122.427") < 25000) 
  AND (strpos(lower(name), "coffee") >= 0 
  OR strpos(lower(description), "coffee") >= 0))
ORDER BY distance(latitude, longitude, "37.76", "-122.427") ASC 
LIMIT 20 OFFSET 0

Problem with this is that the fields name and description are not indexable in the place table. This means that not all the results are returned by the FQL, there are many missing results.


回答1:


It seems like it's possible using this FQL. The contains function seems to work the same as the q= Graph API param. Here's your example using contains

SELECT page_id, name, description, latitude, longitude, checkin_count, distance(latitude, longitude, "37.76", "-122.427")
FROM place
WHERE distance(latitude, longitude, "37.76", "-122.427") < 1000
AND CONTAINS("coffee")
ORDER BY distance(latitude, longitude, "37.76", "-122.427")
LIMIT 20


来源:https://stackoverflow.com/questions/8166500/order-facebook-places-results-by-distance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!