shell pip install django-haystack python INSTALLED_APPS = [ ... 'haystack', ... ] python HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', 'PATH': os.path.join(BASE_DIR, 'whoosh_index'), }, } python from haystack import indexes from .models import MyModel class MyModelIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) def get_model(self): return MyModel def index_queryset(self, using=None): return self.get_model().objects.all() python from haystack.query import SearchQuerySet search_results = SearchQuerySet().filter(content='keyword')


上一篇:
下一篇:
切换中文