django-haystack gives error Unable to open index at search/xapian/xapian_index

472 Views Asked by At

I am attempting to setup a search function on my django site using django-haystack with xapian backend. I followed the directions as per: http://django-haystack.readthedocs.org/en/latest/tutorial.html

When I enter a search it throws the error: Unable to open index at search/xapian/xapian_index

It seems that no search index was created when I ran ./manage.py rebuild_index However, no errors were reported at that time.

I am attempting to index the following model in myapp/models.py:

class MyMsg (models.Model):
    msg = models.TextField(max_length=2000)
    pub_date = models.DateTimeField('date published')
    author = models.ForeignKey(User)
    def __unicode__(self):
        return self.msg

I have the following search index in myapp/search_index.py:

class MyMsgIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    author = indexes.CharField(model_attr='author')
    pub_date = indexes.DateTimeField(model_attr='pub_date')

    def get_model(self):
        return MyMsg

    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())

I am using: haystack 1.2.4 xapian 1.2.12 mac OS X 10.6.8

Thanks in advance for you help.

1

There are 1 best solutions below

5
On

You say you are using Haystack 1.2.4, but you linked to the new 2.x beta documentation. In earlier versions of Haystack you need to add an "auto discover" step.

It involves creating a variable in settings.py called HAYSTACK_SITECONF that points to a haystack configuration module. Inside that module you need to have at least these lines:

import haystack
haystack.autodiscover()

See the tutorial for your version: http://django-haystack.readthedocs.org/en/v1.2.4/tutorial.html

Could this be the problem?