Hi, this is my first question on this forum! Please, take some time to
read this message, since it is very big. (sorry)
I’m building a search engine (crawler) that indexes products data from
more than 500 online brazilian stores. This part is easy => Crawling,
Extracting Information, etc.
I’m running on an app design problem. Different types of products have
different attributes. For instance: Books have :Publisher, :Edition,
:Author, etc… Digital Cameras have :Brand, :Megapixel, etc… and so
on. I REFUSE MYSELF TO CREATE ONE MODEL FOR EVERY TYPE OF PRODUCT.
The crawler automatically discover the types of products and product
attributes per type of product. What I was thinking is to have only one
model => Product. Please see below the design I want to have (if you
have any suggestions, please, tell me).
class Category < ActiveRecord::Base
end
class Product < ActiveRecord::Base
belongs_to :category
end
class AttributeType < ActiveRecord::Base
belongs_to :category
end
class Attribute < ActiveRecord::Base
belongs_to :product
belongs_to :attribute_type
end
The Category model represents the type of product (Books, Digital
Camera) and each category has an Attribute Type set. My application is
just like http://www.pricejunkie.com but specially for brazilian
customers. The customer will be presented with a search field (Sphinx
with Thinking Sphinx or UltraSphinx) and a list of categories.
What exactly is my problem?? Thinking Sphinx FACETS (filters). In this
applications, each facet is an Attribute Type. Please see
http://www.pricejunkie.com, click on the Book category and you will see
what I mean.
The problem is that facets in Thinking Sphinx are defined per model
field. If I had a Book model with the field :autor, I could just do this
with Thinking Sphinx on the Book model:
define_index do
indexes author, :facet => true
end
I need my system to have dynamic facets per product category, otherwise
I will have to create more than 300 different product types…
I hope I made myself clear. PLEASE SOMEONE HELP.
Thanks