From 435309f2e45fe644c72a2413fd52045896ea16c8 Mon Sep 17 00:00:00 2001 From: ptgkifnrw <2043424546@qq.com> Date: Sun, 9 Nov 2025 22:11:29 +0800 Subject: [PATCH] ADD file via upload --- search_indexes.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 search_indexes.py diff --git a/search_indexes.py b/search_indexes.py new file mode 100644 index 0000000..6e42ea3 --- /dev/null +++ b/search_indexes.py @@ -0,0 +1,21 @@ +#zf:从haystack导入索引相关模块 +from haystack import indexes + +#zf:从blog.models导入Article模型 +from blog.models import Article + + +#zf:定义文章索引类,继承自SearchIndex和Indexable +class ArticleIndex(indexes.SearchIndex, indexes.Indexable): + #zf:定义文本字段,作为文档字段,使用模板来确定索引内容 + text = indexes.CharField(document=True, use_template=True) + + #zf:获取模型类的方法 + def get_model(self): + #zf:返回Article模型 + return Article + + #zf:定义索引查询集,确定哪些数据会被索引 + def index_queryset(self, using=None): + #zf:返回所有状态为已发布('p')的文章 + return self.get_model().objects.filter(status='p') \ No newline at end of file