Reputation: 11706
What are the pros and cons of Sunspot Search with Multiple Types vs Single Type? What is the preferred way?
I've looked through a lot of docs and can't seem to find the answers.
Example of Multiple Type Search:
Sunspot.search(Post, Comment) do
with :blog_id, 1
fulltext 'hello' do
fields(:comment_body)
end
end
Example of Single Type Search with association to another Model/Type:
class Post < ActiveRecord::Base
searchable do
text :comments do
comments.map { |comment| comment.body }
end
end
Post.search do
fulltext 'hello' do
fields(:comments)
end
end
It seems I can achieve the same results using either methods (Multiple Types or Single Type).
Upvotes: 2
Views: 674
Reputation: 11706
After heading down the path of multiple type search, let's see if I can provide some answers to my questions.
Cons of Multiple Type Search
Therefore, Single Type Search with associations and mapping to multiple models, which doesn't have any of these issues and can return the same results easily, is preferred IMHO.
Upvotes: 2