2
votes

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.

2

2 Answers

1
votes

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.

1
votes

You have not added which fields you want to search for, in your

search_indexes.py

file. You have to do like:

class PostIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
data = indexes.CharField(model_attr='data', blank=True, null=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)

and then create a directory structure like templates/search/indexes/'app_name'/post_text.txt. Now run command ./manage.py rebuild_index.