如何实现使用位置邻近度作为排名参数的搜索服务
我有一个数据集,需要在其上实现基于位置的搜索服务。我将首先根据关键字参数过滤数据,然后需要根据与用户位置的接近程度对数据进行排序。我该如何实现这一点,关于要使用的算法/方法类型的一些指示,或者数据建模的技巧将非常有帮助。
I have a data set over which I need to implement a location based search service. I will filter the data initially based on keyword arguments and then I need to sort them based on proximity to the user's location. How do I go about implementing this, some pointers on the kind of algorithms/approaches to use, or tips on modeling the data will be really helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用具有地理支持的数据库,例如 postgis:
You could use a database with geo support like postgis:
方法-
你可以想到 Apache Solr(开源搜索引擎)@ http://lucene.apache.org/solr/< /a>
它将帮助您跨关键字搜索并提供地理空间功能。
http://wiki.apache.org/solr/SpatialSearch
注意 - 可能是开销或完全也断章取义,建议只是作为一种选择。由于不确定数据的数量、数据的格式、您需要什么搜索功能。
Approach -
you can think of Apache Solr (open source search engine) @ http://lucene.apache.org/solr/
It will help you to search across keywords and provides geo spatial capabilities.
http://wiki.apache.org/solr/SpatialSearch
Caution - may be an overhead or completely out of context as well, suggested just as an option. As am not sure for the quatity of data, format of the data, what search capabilties you need.
当我向数据库添加列表时,我通过地理编码服务(例如 Google 或 Yahoo)运行地址/邮政编码。然后,我将这些纬度/经度值与列表一起存储。当用户搜索时,我会获取他们的位置,并再次通过地理编码运行该位置,然后我可以按邻近程度进行排序。
类似于这样的:
http://maurus.net/resources/distance-queries/
When I add a listing to my DB, I run the address/postcode though a geocoding service such as Google or Yahoo. I then store these lat/lng values with the listing. When the user searches I take their location and again run this through a geocode, and then I can sort by proximity.
Similar to something like this:
http://maurus.net/resources/distance-queries/
这里有一个想法,您可以在不使用其他服务的 API 的情况下构建它。
我假设您想向客户端显示所有数据。如果没有,您可以使用最小最大纬度、经度值查询数据库以限制区域。
假设客户想要查看距离坐标 x,y 最近的餐馆
从客户端发送 Web 服务查询 showdata(lat,lon,type)
在服务器端:首先查询数据库,选择其中 type == 餐厅。这将为您提供带有经纬度坐标的餐厅列表。您迭代列表并计算距客户端纬度、经度值的距离,并将结果插入到项目列表中。
最后一步,您按距离值对项目列表进行排序并将结果返回给您的客户。
Here's an idea where you build it without using API from other services.
I assume you want to show all the data to the client. If not you could query your DB with min max lat,lon values to restrict the area.
Let's imagine the client wants to see closest restaurants from coordinate x,y
From clientside you send webservice query showdata(lat,lon,type)
At serverside: First you query your DB, select where type == restaurant. This give you a list of restaurants with lat,lon coordinates. You iterate the list and calculate the distance from the clients lat,lon values and insert the result in the items list.
As the last step you sort your items list by Distance value and return the result to your client.