0

I've been following the documentation on Haystack's website on how to add search functionality and I can't get any results to display. I've run this in the shell and everything checks out (count is 433, text isn't just u'').

sqs = SearchQuerySet().all()
sqs.count()
sqs[0].text

At this point using this guide as a reference I came to the conclusion that my search template was the problem, but I'm just using the default template off of Haystack's official tutorial, so I'm not sure what I could be screwing up (i.e. why page.object_list is empty). Here's the relevant portion of the template in question:

{% if query %}
        <h3>Results</h3>

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

        {% if page.has_previous or page.has_next %}
            <div>
                {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
                |
                {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
            </div>
        {% endif %}
    {% else %}
        {# Show some example queries to run, maybe query syntax, something else? #}
    {% endif %}

For good measure, here's my search_indexes.py,

from haystack import indexes
from uchicagohvz.game.models import Kill

class KillIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    killer = indexes.CharField(model_attr='killer')
    victim = indexes.CharField(model_attr='victim')

    def get_model(self):
        return Kill

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

here's my kill_text.txt (located at templates/search/indexes/),

{{ object.killer }}
{{ object.victim }}

here's my search_sites.py (Is this even needed? It's not in the setup tutorial, but I saw it elsewhere while trying to find what was going wrong.)

import haystack
haystack.autodiscover()

and here's my settings.py

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
    },
}
  • What does your view looks like ? – bruno desthuilliers Aug 26 '14 at 06:42
  • I'm using the built-in SearchView linked to in the default URLConf for haystack. My urls.py looks like this: (r'^search/', include('haystack.urls')), I've tried putting this line in the root urls.py and the urls.py for the app where the Kill model is defined and both yield the same error. – user3023718 Aug 27 '14 at 20:13

0 Answers0