我开发了一个电报机器人,它匹配2个用户使用相同的语言,当他们都在寻找带有postgres查询的合作伙伴时。我想根据位置(最近的用户)添加可选的匹配用户的能力。因为它是一个选项,我认为我将默认保持列为null,如果用户发送他的位置,我添加它。我将使用postigs实现这一点。我有两个问题:
如果它可以帮助我的机器人是用python编写的。
非常感谢你
根据第1点,我认为本文将最好地回答您的问题
http://postgis.net/docs/manual-1.5/ch04.html#PostGIS_Geography
关于速度 - 只需在你的geom / geog列上创建gist索引并使用st_Dwithin(geom1,geom2,100)并按st_distance(geom1,geom2)排序结果,它将足够快,直到你有数千万用户。
第2点:是的,它只是联盟
select *, st_distance(u1.geom, u2.geom) dist from
(Select u2.*
from users u1, users u2
where u1.id=1
and u1.id<>u2.id
and st_dwithin(u1.geom, u2.geom, 5000)
UNION
Select * , null dist
from users
where id<>1
and geom is null
LIMIT 1) a
order by dist
我错过了其他标准谎言性别,年龄等,但当然在两个选择中使用它