|
|
|
|
@ -1,13 +1,14 @@
|
|
|
|
|
from haystack import indexes
|
|
|
|
|
from haystack import indexes #ZNY 导入Haystack搜索索引模块
|
|
|
|
|
|
|
|
|
|
from blog.models import Article
|
|
|
|
|
from blog.models import Article #ZNY 导入文章模型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
|
|
|
|
|
text = indexes.CharField(document=True, use_template=True)
|
|
|
|
|
class ArticleIndex(indexes.SearchIndex, indexes.Indexable): #ZNY 定义文章搜索索引类,继承搜索索引和可索引接口
|
|
|
|
|
text = indexes.CharField(document=True, use_template=True) #ZNY 定义主搜索字段,使用模板构建索引内容
|
|
|
|
|
|
|
|
|
|
def get_model(self):
|
|
|
|
|
return Article
|
|
|
|
|
def get_model(self): #ZNY 获取索引对应的模型方法
|
|
|
|
|
return Article #ZNY 返回文章模型类
|
|
|
|
|
|
|
|
|
|
def index_queryset(self, using=None): #ZNY 定义索引查询集方法
|
|
|
|
|
return self.get_model().objects.filter(status='p') #ZNY 只索引已发布状态的文章
|
|
|
|
|
|
|
|
|
|
def index_queryset(self, using=None):
|
|
|
|
|
return self.get_model().objects.filter(status='p')
|
|
|
|
|
|