2013-02-13 78 views
0

我需要通过距传递坐标的距离排序来搜索位置。思维狮身人面像地质问题

应用程序/索引/ 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' 
  • 斯芬克斯2.0.6释放(r3473; 2012年10月22日)
  • thinking-狮身人面像(3.0.1)

更新:

帕特艾伦建议: 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 
+0

我不知道有关思维狮身人面像的真正帮助。但也许尝试添加'compat_sphinxql_magics = 1'(或将现有的行从0改为)sphinx.conf文件。在以后的sphinxql交互中不支持@geodist,所以必须重新启用传统模式。 – barryhunter 2013-02-13 15:12:33

+0

@barryhunter,它没有帮助。但是谢谢你! – 2013-02-13 15:59:42

回答

1

以防万一,人们发现这个问题,以为我想补充答案以正确的格式和更多的解释。

2.1.1之前的Sphinx版本通过@geodist内部变量使计算出的距离可用。在思维狮身人面像与较新版本的狮身人面像兼容的版本中,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 

希望帮助!