zjp注释 #27

Merged
phm9gvnzi merged 2 commits from zjp_branch into develop 4 months ago

@ -0,0 +1,24 @@
from haystack import indexes
# 导入Haystack搜索索引模块
# 导入博客文章模型
from blog.models import Article
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
"""文章搜索索引类用于定义Elasticsearch/Solr等搜索引擎的索引结构"""
# 定义主搜索字段document=True表示这是主要的搜索文档字段
# use_template=True表示使用模板文件来定义字段内容
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
"""返回该索引对应的Django模型类"""
return Article
def index_queryset(self, using=None):
"""
返回需要被索引的查询集
using参数指定使用的搜索引擎后端
"""
# 只索引状态为已发布('p')的文章
return self.get_model().objects.filter(status='p')

@ -0,0 +1,24 @@
from haystack import indexes
# 导入Haystack搜索索引模块
# 导入博客文章模型
from blog.models import Article
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
"""文章搜索索引类用于定义Elasticsearch/Solr等搜索引擎的索引结构"""
# 定义主搜索字段document=True表示这是主要的搜索文档字段
# use_template=True表示使用模板文件来定义字段内容
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
"""返回该索引对应的Django模型类"""
return Article
def index_queryset(self, using=None):
"""
返回需要被索引的查询集
using参数指定使用的搜索引擎后端
"""
# 只索引状态为已发布('p')的文章
return self.get_model().objects.filter(status='p')
Loading…
Cancel
Save