ThinkingSphinx:通过关联运行SQL字符串
我正在尝试通过协会进行地理搜索。与此人非常相似:
How do I geo-search multiple models与 ThinkingSphinx?
一个区别是我尝试将关联语法与自定义 SQL 语法结合起来。它不会打印索引上的任何错误,但是当我尝试搜索时它失败:
class Person
define_index do
indexes tags(:text), :as => :tags
has media.location.lat('RADIANS(location.lat)'), :as => :lat, :type => :float
has media.location.lng('RADIANS(location.lng)'), :as => :lng, :type => :float
end
sphinx_scope(:by_location) { |loc|
{ :geo => [loc.lat.to_radians, loc.lng.to_radians],
:with => {"@geodist" => 0.0..loc.radius },
:latitude_attr => "lat",
:longitude_attr => "lng"
}
}
end
#running this search from console
Person.by_location(Location.first)
这是错误:
ThinkingSphinx::SphinxError:索引fulfillment_core:未知纬度属性“lat”
我尝试在没有SQL字符串的情况下配置它 - 这运行没有错误,但数学当然是完全错误的,因为它试图对度数进行弧度运算。
有什么方法可以将转换和关联结合起来,或者我是否坚持将数据存储为弧度而不是度数?
I'm trying to get a geo search to work via an association. Very similar to this fellow:
How do I geo-search multiple models with ThinkingSphinx?
The one difference is that I'm trying to combine the association syntax with custom SQL syntax. It doesn't print any errors on indexing, but when I try to search it fails:
class Person
define_index do
indexes tags(:text), :as => :tags
has media.location.lat('RADIANS(location.lat)'), :as => :lat, :type => :float
has media.location.lng('RADIANS(location.lng)'), :as => :lng, :type => :float
end
sphinx_scope(:by_location) { |loc|
{ :geo => [loc.lat.to_radians, loc.lng.to_radians],
:with => {"@geodist" => 0.0..loc.radius },
:latitude_attr => "lat",
:longitude_attr => "lng"
}
}
end
#running this search from console
Person.by_location(Location.first)
This is the error:
ThinkingSphinx::SphinxError: index fulfillment_core: unknown latitude attribute 'lat'
I've tried configuring it without the SQL string - this runs without error, but the math is of course totally wrong as it's trying to do radian operations on degrees.
Is there any way to combine the conversion and the association, or am I stuck storing my data as radians instead of degrees?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的索引定义不太正确。请尝试以下操作:
Your index definition isn't quite right. Try the following: