Reputation: 153
I am well versed with Solr and have used it previously using DIH. In the current application that I am working on my Solr document would consist of fields from 3 tables (because of RDBMS design of the db).
Questions
: This is the main table, with the id (question id) being the foreign key to all other tables
Questions and topic mapping
table: Maps multiple topics to single question.
Answers
: Each question can have multiple answers and these are stored in this table with the foreign key from questions table.
Can these two requirements be met with sunspot? If not, is there some other extension available for rails with Solr where I can configure solr separately (through DIH, schema.xml etc.) and use it with functions available in the extension?
Upvotes: 1
Views: 695
Reputation: 3122
I haven't tested this code, but maybe it will get you in the right direction. I know the :if
will definitely work, what I'm not sure of is the use of multiple
on a text field.
class Question < ActiveRecord::Base
has_many :topics
has_many :answers
searchable :if => active? do
text :question_text
text :topics, :multiple => true do
topics.pluck(&:topic_text)
end
# Not sure if `multiple` works with text fields, so alternatively:
#text :topics do
# topics.pluck(&:topic_text).join()
#end
text :answers, :multiple => true do
answers.pluck(&:answer_text)
end
end
end
Upvotes: 1