干草堆没有显示结果

时间:2016-08-08 06:30:52

标签: django django-haystack whoosh

我在模型中搜索术语并没有带来“找不到结果”。我检查了页面的源代码,并且它粗略地显示它在搜索中看到的东西但它没有在浏览器中显示它

<h3>Results</h3>

                <p>
                    <a href=""></a>
                </p>

这是我的模特:

class Feed(models.Model):
    text=models.TextField(blank=False,max_length=5000)
    auth=models.ForeignKey(Authority,blank=False)

search-indexes.py

class FeedIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True,)
    text1 = indexes.CharField(model_attr='text')
    auth = indexes.CharField(model_attr='auth')

    def get_model(self):
        return Feed

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

feed_text.txt

{{ object.text }}
{{ object.auth.name }}

search.html

{% extends 'base.html' %}

{% block content %}
    <h2>Search</h2>

    <form method="get" action=".">
        <table>
            {{ form.as_table }}
            <tr>
                <td>&nbsp;</td>
                <td>
                    <input type="submit" value="Search">
                </td>
            </tr>
        </table>

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

            {% for result in page.object_list %}
                <p>
                    <a href="{{ result.object.get_absolute_url }}">{{result.object.text}}</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 %}
    </form>
{% endblock %}

请帮助我

0 个答案:

没有答案