首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对斯芬克斯地学研究问题的思考

对斯芬克斯地学研究问题的思考
EN

Stack Overflow用户
提问于 2013-02-13 12:38:47
回答 1查看 571关注 0票数 0

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

app/索引/位置_index.rb

代码语言:javascript
复制
ThinkingSphinx::Index.define :location, :with => :active_record do
  indexes :name
  has latitude, longitude
end

试着搜索:

代码语言:javascript
复制
> 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日)
  • 思维-狮身人面像(3.0.1)

更新:

Pat Allan建议: Geodist不再需要@符号--因此请尝试以下方法:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-06-28 07:52:33

万一人们发现这个问题,我会把答案加在正确的格式里,再多解释一下。

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

所以这个:

代码语言:javascript
复制
Location.search(:geo => [53.348962, 83.777988], :order => "@geodist DESC").size

变成:

代码语言:javascript
复制
Location.search(:geo => [53.348962, 83.777988], :order => "geodist DESC").size

在本例中还值得指出的是,在上面的示例中提供的坐标格式不正确。他们是在学位而不是弧度:http://pat.github.io/thinking-sphinx/geosearching.html。要对它们进行转换,您可以:

代码语言:javascript
复制
def degrees_to_radians(degrees)
  degrees * Math::PI / 180
end

希望这能帮上忙!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14853776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档