1

嘿,我一直在努力让 haystack 与 whoosh 一起为我一直在从事的 django cms 项目实施搜索后端。在找出一些非常奇怪的权限错误之后,我几乎可以尝到成功的滋味。

我现在有 haystack 正确创建索引,它甚至会显示我创建索引的自定义应用程序的结果,但是我无法让它显示 cms 页面内容的任何结果。由于我没有收到“无结果”消息,因此返回了结果,但在 results.html 模板中没有打印任何内容。

请记住,我让 django-cms-search 处理 cms 应用程序的索引,我认为我不需要添加任何额外内容来显示结果。

因此,概述一下我到目前为止使用 Whoosh 后端安装的 Haystack

我的setting.py设置是

HAYSTACK_SITECONF = 'lactoseintolerant.lactose_search.search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = '/home/mike/sites/lactosetoloerant/lactoseintolerant/whoosh'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 50

我的search_sites.ph文件看起来像

import haystack
from cms.models import monkeypatch_reverse
from cms.plugin_pool import plugin_pool

monkeypatch_reverse()    
haystack.autodiscover()

我的主题模型有一个自定义索引,看起来像这样(这正在工作并恢复 Reuslts)

from topics.models import Topic 
from haystack.indexes import *
from haystack import site


class TopicIndex(SearchIndex):
    text = CharField(document=True, use_template=True)

    def index_queryset(self):
        """
        This is used when the entire index for model is updated, and should only include
        public entries
        """
        return Topic.objects.filter(active=True)



site.register(Topic, TopicIndex)

我的results.html模板看起来像

{% extends "base.html" %}
{% load cache cms_tags menu_tags %}
{% block base_content %}

    <div id="panel-left">
        {% block nav %}
            <ul id="nav-left">
                {% show_menu 1 100 100 100 %}
            </ul> <!-- #nav-left -->
        {% endblock %}

        {% block panel_left %}

        {% endblock %}
    </div>

    {% block panel_right %}

        <div id="panel-main">           
            {% ifequal q '' %}
                <h1 id="page-head-2">Search Results Page</h1>
                <p>Please provide search criteria or keywords</p>
                <br />
                <form action=".">
                    <p>
                        <input type="text" name="q" value="{{ q }}">
                        <input type="submit" name="search" value="Search">
                    </p>
                </form>
            {% else %}
                <h1 id="page-head-2">Search Results - page {{ request.GET.page|default:1 }} of {{ paginator.num_pages }}</h1>
                <h1 id="page-head-2">Found {{ paginator.count }} for <span id="searchString">'{{ q }}'</span></h1>
                <form action=".">
                    <p>
                        <input type="text" name="q" value="{{ q }}">
                        <input type="submit" name="search" value="Search">
                    </p>
                </form>

                <ul id="searchResults">
                    {% for item in current_page.object_list %}

                        <li class="searchResult">
                                <h2 class="searchTitle">{{ forloop.counter }}. {{ item.get_title }}</h2>
                                <a class="searchLink" href="{{ item.get_absolute_url }}">{{ item.get_absolute_url }}</a>
                        </li> <!-- .searchResult -->

                    {% endfor %}
                </ul>

                {% if paginator.num_pages > 1 %}
                    <div id="pagination">
                        {% for page_range_item in paginator.page_range %}
                                {% if not request.GET.page and page_range_item == 1 or request.GET.page == page_range_item|safe %}
                                    <span class="pag-link current" href="/topics/?page={{ page_range_item }}">{{ page_range_item }}</span>
                                {% else %}
                                    <a class="pag-link" href="/search/?q={{ q }}&page={{ page_range_item }}">{{ page_range_item }}</a>
                                {% endif %}
                        {% endfor %}
                    </div>
                {% endif %}

            {% endifequal %}

        </div>      
     {% endblock %}


     {% endblock %}

我显然在这里遗漏了一些明显的东西,任何帮助将不胜感激!

干杯

4

1 回答 1

0

我想你差不多明白了,试着改变{{ item.get_absolute_url }}{{ item.object.get_absolute_url }}results.html文件。

于 2013-02-11T12:53:34.407 回答