|
|
|
@ -1,7 +1,12 @@
|
|
|
|
# 定义 Haystack 的搜索索引,用于普通搜索(非 Elasticsearch)
|
|
|
|
from haystack import indexes
|
|
|
|
|
|
|
|
from blog.models import Article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
|
|
|
|
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
|
|
|
|
text = indexes.CharField(document=True, use_template=True)
|
|
|
|
text = indexes.CharField(document=True, use_template=True)
|
|
|
|
|
|
|
|
|
|
|
|
def get_model(self):
|
|
|
|
def get_model(self):
|
|
|
|
return Article
|
|
|
|
return Article
|
|
|
|
|
|
|
|
|
|
|
|
def index_queryset(self, using=None):
|
|
|
|
def index_queryset(self, using=None):
|
|
|
|
return self.get_model().objects.filter(status='p') # 只索引已发布文章
|
|
|
|
return self.get_model().objects.filter(status='p')
|