I have two models in Django like follows(in pseudo code)
class Medicine(db.Model):
field_1 = db.CharField()
field_2 = db.CharField()
class Application(db.Model):
field_1 = db.CharField()
field_2 = db.CharField()
medicine = db.ForeignKey(Medicine)
There is a 1:M. One medicine can have many applications.
I need to facet on the fields of Application but only show related Medicine objects. Something like DISTINCT in SQL.
What would be the most straight forward way to accomplish this with haystack?
Do I make SearchIndex for Medicine or Application? If I make SearchIndex for Application, how do I detect/filter duplicate Medicine objects?
PS: I know there’s Field Collapsing feature in dev releases of Solr, but I want to avoid doing that, becuase it is huge database and performance critical.
I solved this with the help of Daniel Lindsay(Haystack/pySolr author) on haystack mailing list.
Indexing takes some time as the data to be indexed is huge is huge, but worked like a charm.