django-haystackxapian

Django-haystack not updating index


Using django-haystack 2.0.0 and xapian-haystack 2.0.0, migrated all code from 1.1.5 as it said in docs. Now my search_indexes.py looks like:

from haystack import indexes
from app.models import Post

class PostIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    def get_model(self):
        return Post

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(visible=True)

But when I go rebuild_index, it says:

Are you sure you wish to continue? [y/N] y

Removing all documents from your index because you said so. All documents removed.

With verbosity:

Skipping '<class 'django.contrib.auth.models.Permission'>' - no index.
Skipping '<class 'django.contrib.auth.models.Group'>' - no index.
...
Skipping '<class 'app.models.Post'>' - no index.

So, I don't know why haystack doesn't index this model.


Solution

  • You have to actually add fields to your index, so under "text" add:

    post1 = indexes.CharField(model_attr='postfield1', null=True)
    

    And then in your post_text.txt index file template:

    {{object.post1}}
    

    Now it should work.