使用 django-haystack 和 Spatial Solr 插件对多个位置进行半径搜索

发布于 2024-11-06 08:10:25 字数 674 浏览 6 评论 0原文

我有一个 Person 模型,现在可以有多个办公室“位置”,每个位置都有自己的纬度/经度。

在只能添加 1 个办公室之前,我一直在使用我为 django-haystack 制作的一个叉子,它使用 JTeam 的 Spatial-solr-plugin 来进行半径搜索。请参阅 https://github.com/sidmitra/django-haystack

class PersonIndex(indexes.SearchIndex):
    lat = indexes.FloatField()
    lng = indexes.FloatField()

sqs.spatial(lat=lat, long=lng, radius=radius, unit=kwargs.get('unit'))

因为办公室数量不受限制,我无法在索引中使用单独的 lat/lng 字段。

我能想到的一种方法是索引“位置”模型。每个位置都是索引中的一个单独条目。因此解决了这个问题,但这意味着将人员索引中的所有字段复制到该位置索引。虽然这在短期内可能是一个不错的解决方案,但从长远来看可能会很混乱?

想知道是否有一种方法可以单独索引位置,然后根据指定半径内的地址过滤相关人员?

I have a Person model which now can have a number of office "locations", each with its own latitude/longitude.

Before one could add only 1 office, So i'd been using a fork I made for django-haystack that uses JTeam's spatial-solr-plugin to do radius search. See https://github.com/sidmitra/django-haystack

class PersonIndex(indexes.SearchIndex):
    lat = indexes.FloatField()
    lng = indexes.FloatField()

sqs.spatial(lat=lat, long=lng, radius=radius, unit=kwargs.get('unit'))

Since the number of offices are unlimited, i can't use separate lat/lng fields in the index.

One way i could think of was to index the "Location" model instead. Each location would be a seperate entry in the index. Thus solving this problem, but would mean replicating all of the fields from the Person index to this location index. Although this might be a decent solution in the short term, but would probably be untidy in the long run?

Wondering if there's a way to index locations separately and then filter related Person, based on the addresses that are within the specified radius?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文