ThinkingSphinx:通过关联运行SQL字符串

发布于 2024-10-29 02:57:16 字数 1080 浏览 0 评论 0原文

我正在尝试通过协会进行地理搜索。与此人非常相似:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦归所梦 2024-11-05 02:57:16

您的索引定义不太正确。请尝试以下操作:

define_index do
  indexes tags(:text), :as => :tags

  # forces the join on media and location associations
  join media.location

  has 'RADIANS(location.lat)', :as => :lat, :type => :float
  has 'RADIANS(location.lng)', :as => :lng, :type => :float
end

Your index definition isn't quite right. Try the following:

define_index do
  indexes tags(:text), :as => :tags

  # forces the join on media and location associations
  join media.location

  has 'RADIANS(location.lat)', :as => :lat, :type => :float
  has 'RADIANS(location.lng)', :as => :lng, :type => :float
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文