Rails 3.x 中使用 Solr (websolr) 进行地理空间搜索

发布于 2024-12-28 12:23:48 字数 442 浏览 1 评论 0原文

我希望在 Rails 3.1 应用程序中利用 Solr 进行文本和地理空间搜索。我看到 websolr 支持地理空间索引和搜索但有两个宝石(sunspot & rsolr) 似乎(当前)没有实现它。 Sunspot 似乎正在添加该功能,但声称“[地理空间] 处于实验阶段且尚未发布。DSL 可能会发生变化。”

是否有其他使用 sunspot + websolr 进行地理空间搜索的实现?我做了一些搜索并遇到了一些,但它们看起来很老套,如果已经有核心功能或更受支持的方法,我宁愿不使用我发现的东西。

I am looking to utilize Solr for both text and geospatial searching in a Rails 3.1 app. I see that websolr supports geo-spatial indexing & searches but the two gems for it (sunspot & rsolr) do not seem to (currently) implement it. Sunspot appears to be in the process of adding the functionality but claims that "[geospatial is] experimental and unreleased. The DSL may change."

Are there other implementations of geospatial searching with sunspot + websolr? I've done a bit of googing and come across some but they seem hackish and I'd rather not use what I've found if there is already a core feature being baked in or a more supported approach.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我早已燃尽 2025-01-04 12:23:48

Sunspot 确实支持地理空间搜索,但有一些限制。

索引:

searchable do
  text :location
  location :coordinates do
    Sunspot::Util::Coordinates.new latitude, longitude
  end
end

搜索:

coord = # whatever...
with(:coordinates).near(coord[0], coord[1], :precision => 3)

但它确实不精确......如果我没记错的话,它使用地理哈希。因此,有可能有 2 个点彼此很接近,但没有找到。
另外,您不能在构面附近嵌套。

我会遵循 ADAM 的建议并进行弹性搜索。我就是这么做的。你可以获得更多的控制权。

Tire 还支持地理空间搜索,但 DSL 中没有具体方法,因为不需要。我想他们计划稍后添加。

索引:

tire.mapping do
    indexes :location, type: 'string', analyzer: 'snowball'
    indexes :latitude_longitude, type: 'geo_point'
end

def latitude_longitude
    [latitude, longitude].join(",")
end

def to_indexed_json
    to_json(methods: ['latitude_longitude'])
end

搜索:

filter :geo_distance, distance: "#{distance}km", latitude_longitude: [user.latitude, user.longitude].join(",")

Sunspot does support geo-spatial search, with some limitations.

Indexing:

searchable do
  text :location
  location :coordinates do
    Sunspot::Util::Coordinates.new latitude, longitude
  end
end

Search:

coord = # whatever...
with(:coordinates).near(coord[0], coord[1], :precision => 3)

But it's really not precise... It's using geo hashes if I'm not mistaken. So it's possible that 2 points are close from each other but are not found.
Also, you can't nest near in facets.

I would follow the advice of ADAM and go for elastic search. That's what I did. You get a lot more control.

Tire also supports geospatial search, but there is no specific methods in the DSL, because it's not needed. They plan to add them later I think.

Indexing:

tire.mapping do
    indexes :location, type: 'string', analyzer: 'snowball'
    indexes :latitude_longitude, type: 'geo_point'
end

def latitude_longitude
    [latitude, longitude].join(",")
end

def to_indexed_json
    to_json(methods: ['latitude_longitude'])
end

Search:

filter :geo_distance, distance: "#{distance}km", latitude_longitude: [user.latitude, user.longitude].join(",")
我只土不豪 2025-01-04 12:23:48

对于后代:Sunspot 已发布版本 1.3.0,支持 Solr 3 空间搜索,使其成为 Heroku 上与 Websolr 完美可行的选项。

For posterity: Sunspot has since released version 1.3.0 with support for Solr 3 spatial search, making it a perfectly viable option on Heroku with Websolr.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文