邻近搜索 [英] Proximity Search

查看:81
本文介绍了邻近搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序如何执行邻近搜索?例如,用户输入邮政编码,然后该应用程序将按距离排序列出20英里内的所有企业.

How does an application perform a proximity search? For example, a user types in a postal code, then the application lists all the businesses within 20 miles ordered by proximity.

我想在PHP和MySQL中构建类似的东西.这种方法正确吗?

I want to build something like that in PHP and MySQL. Is this approach correct?

  1. 获取我感兴趣的位置的地址并将其存储在数据库中
  2. 使用Google的地理编码服务对所有地址进行地理编码
  3. 编写一个包含Haversine公式的数据库查询以进行邻近搜索和排序

这样可以吗?在第3步中,我将计算每个查询的接近度.最好有一个PROXIMITY表,该表列出每个企业与几个参考位置之间的距离?

Is this OK? In step 3, I'm going to calculate the proximity for every query. Is it better to have a PROXIMITY table that lists the distance between every business and a few reference locations?

推荐答案

如果有足够的记录要考虑的速度,那么可以使用这种方法提前对其进行索引.

If there are enough records for speed to matter, here's a way to index them ahead of time.

在侧面定义约20英里的垃圾箱网格.将bin编号与每个商店的记录一起存储.在搜索时,计算与搜索点相距20英里半径的所有垃圾箱的数量.然后在这些垃圾箱中的任何一个中检索所有商店,并像以前一样继续进行.

Define a grid of bins about 20 miles on a side. Store the bin number with each store's record. At search time, compute the numbers of all bins that intersect a 20-mile radius from your search point. Then retrieve all stores in any of those bins, and proceed as before.

这篇关于邻近搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆