2013-02-13 6 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 파일에 추가 해보십시오. @geodist는 sphinxql의 나중 버전에서 지원되지 않으므로 레거시 모드를 다시 활성화해야합니다. – barryhunter

+0

@barryhunter, 그것은 도움이되지 못했습니다. 하지만 고마워! –

답변

1

경우 사람들은이 질문에 내가 대답을 추가 할 거라고 생각 찾을 단지에 올바른 형식과 조금 더 설명합니다.

2.1.1 이전의 스핑크스 버전은 계산 된 거리를 @geodist 내부 변수를 통해 사용할 수있게했습니다. 새로운 스핑크스 버전과 호환되는 Thinking Sphinx 버전에서는 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 

희망이 있습니다!