Ruby on rails 如何使用ThinkingSphinx对多个模型进行地理搜索?
我有两个用于搜索的索引模型(用户和项目)。我正在尝试跨模型进行地理搜索:Ruby on rails 如何使用ThinkingSphinx对多个模型进行地理搜索?,ruby-on-rails,ruby,sphinx,thinking-sphinx,Ruby On Rails,Ruby,Sphinx,Thinking Sphinx,我有两个用于搜索的索引模型(用户和项目)。我正在尝试跨模型进行地理搜索: ThinkingSphinx::Search.Search('keywords',:geo=>[ 度到弧度(参数[:lat]。到f), 度到弧度(参数[:lon]。到f) ], ) 但我只得到一个错误: Sphinx错误:索引项\u核心、项\u增量、用户\u核心、用户\u增量:未知纬度属性“” 单独搜索每个模型效果很好。。。但我不知道这里有什么问题。以下是索引: 用户索引: define_index do inde
ThinkingSphinx::Search.Search('keywords',:geo=>[
度到弧度(参数[:lat]。到f),
度到弧度(参数[:lon]。到f)
],
)
但我只得到一个错误:
Sphinx错误:索引项\u核心、项\u增量、用户\u核心、用户\u增量:未知纬度属性“”
单独搜索每个模型效果很好。。。但我不知道这里有什么问题。以下是索引:
用户索引:
define_index do
indexes [:first_name, :last_name], :as => :name
indexes login
indexes email
indexes headline
indexes description
indexes business.name, :as => :business_name
indexes [addresses.street_1, addresses.street_2, addresses.city, addresses.postal_code], :as => :address
has created_at, :sortable => true
has addresses.latitude, :as => :latitude, :type => :float
has addresses.longitude, :as => :longitude, :type => :float
set_property :delta => true
end
项目索引:
define_index do
indexes title, :sortable => true
indexes description
indexes [address.street_1, address.street_2, address.city, address.postal_code], :as => :address
indexes images.title, :as => :image_titles
indexes images.description, :as => :image_descriptions
indexes categories(:name), :as => :category_names
has price, :sortable => true
has created_at, :sortable => true
has address.latitude, :as => :latitude, :type => :float
has address.longitude, :as => :longitude, :type => :float
has categories(:id), :as => :category_ids
where "`items`.`state` = 'for_sale'"
set_property :delta => true
end
这是一个迟来的答复,但总比没有好,希望: 当您不搜索特定模型时,认为Sphinx没有了解哪些属性可用的参考点,因此您需要明确告诉它要使用的lat和long属性:
ThinkingSphinx::Search.search('keywords',
:geo => [
degrees_to_radians(params[:lat].to_f),
degrees_to_radians(params[:lon].to_f)
],
:latitude_attr => "latitude",
:longitude_attr => "longitude"
)