I have four tables. They are Brands, departments, categories and product_details. The models are
Brand model
class Brand < ActiveRecord::Base
has_many :product_details, :dependent=>:destroy
searchable do
integer :id
text :name
end
end
Deparment model
class Department < ActiveRecord::Base
has_many :product_details, :dependent=>:destroy
searchable do
integer :id
text :name
end
end
Category model
class Category < ActiveRecord::Base
has_many :product_details, :dependent=>:destroy
searchable do
integer :id
text :name
end
end
ProductDetail model
class ProductDetail < ActiveRecord::Base
belongs_to :department
belongs_to :category
belongs_to :brand
searchable do
text :name
text :brand do
brand.name
end
integer :department_id
integer :category_id
end
If user searches for department 1 first I have get all product details based on department id. The resultant table must contain brand name, category name and department name also. Is it possible to do it using sunspot solr? How?
I think you should create a Document for each Product with Brand, Department, Category and Product details.
Then you're able to search for what you want, and receive the information you need.