solution:
I finally found the problem, I had some issues in my development database where Profile was not having a Match. + some missing profile_id in the match table, after fixing those the reindex went fine.
Question
Want to easy search all associated model attributes Asked before still problems with this:
Profile model
has_one :match
searchable do
integer :id
string :country
string :state
string :city
end
Match model
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
Rewrote the searchable block like in first answer suggestion with a :looking_for_education do block. Still fails with a undefined method `looking_for' for #
Added integer :id to the indexes still same issue :(
Solution 2
I finally found the problem, I had some issues in my development database where Profile was not having a Match. + some missing profile_id in the match table, after fixing those the reindex went fine.
OTHER TIPS
The problem is that you're trying to search on BOTH Profile
and Match
at once, but the models are indexed as separate documents and Sunspot.search Profile do
only searches Profile
documents.
You need to configure the documents to contain all the information you need in one document. One way to do this could be making the Profile
be the document that contains all the information:
class Profile
has_one :match
searchable do
string :country
string :state
string :city
string :looking_for_education do
match.looking_for_education
end
end