7

Suggestions needed for creating better and efficient search indexes for models having foreign key and many-to-many fields while using haystack with django.

Sample Model:

class Resource(models.Model):
   title = models.CharField(max_length=255)
   description = models.TextField(blank=True, null=True)
   content = models.ForeignKey(ResourceContent, unique=True)
   metadata = models.ManyToManyField(MetaData)
Neo
  • 5,070
  • 10
  • 46
  • 65
  • 2
    perhaps an example of the index you have already created would help to see how it can be improved – Mike Waites Sep 11 '11 at 20:34
  • Could you clarify the question a bit with an example of what you are searching for? – Wolph Oct 25 '11 at 14:29
  • You can use custom `prepare` functions for some fields and put there all you need from related objects (http://docs.haystacksearch.org/dev/searchindex_api.html#prepare-foo-self-object). – rootart Nov 13 '11 at 09:47

1 Answers1

5

you don't need to declare

metadata = models.ManyToManyField(MetaData)

instead use looping inside index template easy where best practise says in doc

Related Data

Related data is somewhat problematic to deal with, as most search engines are better with documents than they are with relationships. One way to approach this is to de-normalize a related child object or objects into the parent’s document template. The inclusion of a foreign key’s relevant data or a simple Django {% for %} templatetag to iterate over the related objects can increase the salient data in your document. Be careful what you include and how you structure it, as this can have consequences on how well a result might rank in your search

http://docs.haystacksearch.org/dev/best_practices.html?highlight=loop

ghostJago
  • 3,381
  • 5
  • 36
  • 51
soField
  • 2,536
  • 9
  • 36
  • 44