2013-02-13 22 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 

希望幫助!