0

関連するすべてのモデル属性を簡単に検索したい前に質問されましたが、これにはまだ問題があります:

プロファイル モデル

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

ProfilesController#Index

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

:looking_for_education do ブロックを使用して、最初の回答の提案のように検索可能なブロックを書き直しました。まだ未定義のメソッド「looking_for」で失敗する #

整数:idをインデックスに追加しても同じ問題:(

4

2 に答える 2

1

Profile問題は、両方を一度に検索しようとしているMatchのに、モデルが個別のドキュメントとして索引付けされ、ドキュメントSunspot.search Profile doのみを検索することProfileです。

1 つのドキュメントに必要なすべての情報が含まれるようにドキュメントを構成する必要があります。これを行う 1 つの方法は、Profileすべての情報を含むドキュメントにすることです。

class Profile
  has_one :match

  searchable do
    string :country
    string :state
    string :city
    string :looking_for_education do
      match.looking_for_education
    end
  end
于 2013-10-18T01:41:40.270 に答える
0

解決:

私は最終的に問題を発見しました.プロファイルが一致しない開発データベースにいくつかの問題がありました. + マッチ テーブルに profile_id がいくつかありませんでした。これらを修正した後、インデックスの再作成はうまくいきました。

于 2013-10-18T08:29:13.547 に答える