如何Django + Haystack +多站点?

时间:2011-05-26 12:39:22

标签: django-haystack

为多站点配置django-haystack的正确/最佳方法是什么?

目前一切正常但结果并不局限于当前网站。

1 个答案:

答案 0 :(得分:2)

<强> indexes.py

from haystack.indexes import SearchIndex, IntegerField

class SiteSearchIndex(SearchIndex):
    site_id = IntegerField(model_attr="site__id")

我的search_indexes继承自该类。

<强> urls.py

from django.conf import settings
from django.conf.urls.defaults import patterns, url
from haystack.forms import SearchForm
from haystack.query import SearchQuerySet
from haystack.views import search_view_factory
from myapp.apps.search.views import SearchView

sqs = SearchQuerySet().filter(site_id=settings.SITE_ID).order_by("-pub_date")
urlpatterns = patterns("",
    url(r"^$",
        search_view_factory(
            view_class=SearchView, searchqueryset=sqs, form_class=SearchForm
        ),
        name="search-index"
    ),
)