I'm trying to integrate a search with django-haystack,
While it works well with the "sample" backend, when replacing the backend with whoosh it always returns 0 results.
settings.py:
HAYSTACK_DEFAULT_OPERATOR = 'AND'
HAYSTACK_SITECONF = 'search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 20
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, 'search_index')
search_sites.py
import haystack
haystack.autodiscover()
profiles/search_indexes.py:
from haystack import indexes
from haystack import site
from profiles.models import Profile
class ProfileIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
def index_queryset(self):
"""Used when the entire index for model is updated."""
return Profile.objects.all()
site.register(Profile, ProfileIndex)
templates/search/indexes/profiles/profile_text.txt:
{{ profile.name }}
{{ profile.description }}
Running python manage.py rebuild_index
returns:
All documents removed.
Indexing 60 profiles.
When running the following in the shell:
>>> from haystack.query import SearchQuerySet
>>> sqs = SearchQuerySet().all()
>>> sqs.count()
0
When switching whoosh with the "simple" backend, everything works fine and 60 results are returned.
Everything seems to be set up correctly, according to Getting Started with Haystack, and Debugging Haystack.
I tried installing previous version of Whoosh, without any success.
Feeling very stupid at this point, any help will be really appreciated.
Package Versions:
python==2.7
Django==1.3.1
Whoosh==2.3.2
django-haystack==1.2.6
Updates:
Ok, found it, and it was even more stupid then I though...
templates/search/indexes/profiles/profile_text.txt
should be:
{{ object.name }}
{{ object.description }}
And not:
{{ profile.name }}
{{ profile.description }}
What confused me was that the "simple" backend that matches against the database, and apparently ignores the data template.