Ruby on rails 太阳黑子轮廓,匹配搜索关联的模型属性结果

Ruby on rails 太阳黑子轮廓,匹配搜索关联的模型属性结果,ruby-on-rails,solr,sunspot,associated-object,Ruby On Rails,Solr,Sunspot,Associated Object,要轻松搜索所有关联的模型属性吗 之前被问及此问题时: 配置文件模型 has_one :match searchable do integer :id string :country string :state string :city end 匹配型号 belongs_to :profile searchable do integer :id string :looking_for_education do

要轻松搜索所有关联的模型属性吗 之前被问及此问题时:

配置文件模型

has_one :match

searchable do
  integer       :id
  string        :country
  string        :state
  string        :city
end
匹配型号

belongs_to :profile

searchable do
  integer :id
  string :looking_for_education do
   match.looking_for_education
  end      
  integer :age_from
  integer :age_to
end
档案控制器#索引

def index

  @search = Sunspot.search Profile do

    with(:country, params[:country]) # this is a profile attribute
    with(:state,   params[:state])   # this is a profile attribute   
    with(:looking_for_education, "high school") # this should search *inside* 
                                                #the match attribute's, 
                                                #where **match** belongs_to 
                                                #**profile**
  end

  @profiles = @search.results

end
编辑#1 重写可搜索块,如第一个答案建议中的:查找教育do块。对于未定义的“查找”方法,仍然失败#


在索引中添加整数:id仍然是同一个问题:(

问题是您试图同时搜索
配置文件
匹配文件
,但是模型作为单独的文档和
Sunspot.search Profile do
只搜索
配置文件
文档

您需要在一个文档中包含所需的所有信息。一种方法是使
配置文件成为包含所有信息的文档:

class Profile
  has_one :match

  searchable do
    string :country
    string :state
    string :city
    string :looking_for_education do
      match.looking_for_education
    end
  end
解决方案:
我终于发现了问题,我的开发数据库中有一些问题,配置文件不匹配。+匹配表中缺少一些配置文件id,在修复这些问题后,重新索引正常。

self.Match.looking\u for\u education,Match.looking\u for\u education和您的建议都会导致n的未定义方法“looking\u for\u education”伊尔:我的班级。