Search code examples
djangodjango-haystackwhoosh

Django-Haystack returns no results in search form


I am using Django-Haystack with Whoosh backend. When I do a query I get no results. I tried the debugging steps suggested in the Haystack docs by typing the following into a Django shell, and I can see that all the text I want has been indexed.

from haystack.query import SearchQuerySet
sqs = SearchQuerySet().all()
sqs.count()
sqs[0].text

My search.html page has the following section (copied straight from the documentation):

{% for result in page.object_list %}
    <p>
        <a href="{{ result.object.url }}">{{ result.object }}</a>
    </p>
{% empty %}
    <p>No results found.</p>
{% endfor %}

What else can I try?


Solution

  • Well, I have no idea what's happening, but whereas in the examples page.object_list works, in my real project I needed to remove the page prefix. Painful to figure out.

    Now this works:

    {% for result in object_list %}
      <p>
        <a href="{{ result.object.url }}">{{ result.object }}</a>
      </p>
    {% empty %}
      <p>No results found.</p>
    {% endfor %}