我需要搜索与传递坐标的距离排序的位置。
app/索引/位置_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'更新:
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发布于 2014-06-28 07:52:33
万一人们发现这个问题,我会把答案加在正确的格式里,再多解释一下。
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希望这能帮上忙!
https://stackoverflow.com/questions/14853776
复制相似问题