【问题标题】:Thinking sphinx geosearch issues思考狮身人面像地理搜索问题
【发布时间】:2014-06-28 15:52:33
【问题描述】:

我需要按与传递坐标的距离排序来搜索位置。

app/indices/location_index.rb

ThinkingSphinx::Index.define :location, :with => :active_record do
  indexes :name
  has latitude, longitude
end

尝试搜索:

> Location.search(:geo => [53.348962, 83.777988], :order => "@geodist DESC").size
ThinkingSphinx::SyntaxError: sphinxql: syntax error, unexpected USERVAR, expecting IDENT (or 5 other tokens) near '@geodist DESC LIMIT 0, 20; SHOW META'

> Location.search(:geo => [53.348962, 83.777988],:with => {"@geodist" => 0.0..5000.0}, :order => "@geodist DESC").size
ThinkingSphinx::SphinxError: sphinxql: only >=, <=, and BETWEEN floating-point filter types are supported in this version near '@geodist BETWEEN 0.0 AND 5000.0 AND sphinx_deleted = 0 ORDER BY @geodist DESC LIMIT 0, 20; SHOW META'
  • Sphinx 2.0.6 版本(r3473;2012 年 10 月 22 日)
  • 思考狮身人面像 (3.0.1)

更新:

Pat Allan 建议: Geodist 不再需要 @ 符号 - 请尝试以下操作:

Location.search(:geo => [53.348962, 83.777988], :order => "geodist DESC").size
Location.search(:geo => [53.348962, 83.777988],:with => {:geodist => 0.0..5000.0}, :order => "geodist DESC").size

【问题讨论】:

  • 我对thinking-sphinx的了解并不多,无法真正提供帮助。但也许可以尝试将 `compat_sphinxql_magics = 1' (或将现有行从 0 更改为)到您的 sphinx.conf 文件。在 sphinxql 的后续交互中不支持 @geodist,因此必须重新启用旧模式。
  • @barryhunter,它没有帮助。不过谢谢!

标签: ruby-on-rails sphinx thinking-sphinx


【解决方案1】:

以防万一人们发现这个问题,我会以正确的格式添加答案并提供更多解释。

2.1.1 之前的 Sphinx 版本通过 @geodist 内部变量提供计算距离。在与新版本 Sphinx 兼容的 Thinking Sphinx 版本中,GEODIST() 的值已别名为 geodist。

所以这个:

Location.search(:geo => [53.348962, 83.777988], :order => "@geodist DESC").size

变成:

Location.search(:geo => [53.348962, 83.777988], :order => "geodist DESC").size

在此示例中还值得指出的是,上例中提供的坐标格式不正确。它们是度数而不是弧度:http://pat.github.io/thinking-sphinx/geosearching.html。要转换它们,您可以这样做:

def degrees_to_radians(degrees)
  degrees * Math::PI / 180
end

希望有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多