0

I followed the Haystack tutorial to set up for Whoosh

>>> pip install whoosh

settings.py

import os
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
    },
}

and I am getting an empty list

>>> list(ix.searcher().documents())
[]

Following is my code for searcher_indexes.py

from haystack import indexes
from view_links.models import Projdb

class ProjdbIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    author = indexes.CharField(model_attr = 'owner')
#   pub_date = indexes.DateTimeField(model_attr='date_start')

    def get_model(self):
        return Projdb

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

I was previously able to get results for elasticsearch but when I shifted to Whoosh I am getting no results.

Thank you for your time. If you require further information, please let me know.

EDIT:

I am getting results now and here are two things I learned.

  1. I need to register the app whose model is being used for indexing.
  2. If a Model's class is misspelled in search_indexes.py, running the python manage.py rebuild_index does not throw any error and you will get zero indexed objects
Ent
  • 11
  • 1
  • 4

1 Answers1

1

Did you run the command?

./manage.py rebuild_index

Do you have any Projdb records?

You have this in your code:

text = indexes.CharField(document=True, use_template=True)

Have you set-up the corresponding template (projdb_text.txt)?

François Constant
  • 5,531
  • 1
  • 33
  • 39
  • I thought I didn't need to register the app whose model I was using. That was the mistake I made. – Ent Feb 19 '14 at 09:10