2

I'll give an example of data. (purely for demonstration, I don't know much about car)

Top category,

Car, Computer, Shoes, ..

Car has many facets.(sub category)

Car - 2 door/4 door  
Car - Audi/Bmw/..

Sub category can have another sub category.

Audi - A series/S series/R series  

Now, product can have multiple parents.

Audi A4 -child of- A series - Audi - Car 
Audi A4 -child of- 4 door  - Car (one shorter depth)

How would I model this in DB?

I've looked at a few RDBMS-only approaches for searching capability, and it looks awful to maintain.
I'm looking at django-haystack, solr approach.
But still I need to model this in django's models.py.

How would I do this and make a search index for haystack?

I'm new to whole django/haystack/solr.
I looked at solr's example document.
It looks like each item has all the necessary data in it.(I guess people call it flattened-data?)

Can I somehow separate meta-data(category trees) from data(actual product item) in DB?
I just feel that's the right approach, am I wrong?

  • EDIT

I forgot to mention that I'd like to use solr's faceted search capability.
So after modeling it in DB, how would my search_indexes.py look like for haystack?

eugene
  • 39,839
  • 68
  • 255
  • 489
  • Check this [answer to another question](http://stackoverflow.com/a/11318758/279564) mentioning subtypes & supertypes. – Rafa Jul 03 '12 at 21:00

1 Answers1

0

These are two different things.

One is you want to store multiple properties for an item. For this, if you want to use a relational database use the entity-attribute-value pattern. eav-django provides this implementation for django.

However, a more flexible (and less cumbersome) approach would be to use a document database (like couch) or other NoSQL solutions. These provide a flexible schema so you don't have to worry about how many "properties" or "meta-data" you have to store about a particular object/item.

The other part of your question is maintaining a tree of relationships with n-depth. This is implemented using the nested set model (also called modified pre-order tree traversal). Like eav, there is django-mptt.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • Thanks for the suggestion. I don't completely grasp EAV, but it looked hell complex to maintain, and nested set model doesn't seem to support multiple parents(categories). Then I found solr faceted search is capable of doing what I want. Hoever as I mentioned in the post, solr example has all the meta-data and data in a single file. I'd like to separate meta-data from data and store them in DB, and at the same time use solr faceted search capability. I hope it makes sense. – eugene Apr 16 '12 at 08:36