为多站点配置django-haystack的正确/最佳方法是什么?
目前一切正常但结果并不局限于当前网站。
答案 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"
),
)