def indexing(self): from yablog.models4es import BlogPostIndex obj = BlogPostIndex( meta={'id': self.id}, title=self.title, content=self.content, char_num=self.char_num, allow_comments=self.allow_comments, vote_num=self.vote_num, category=self.category.name, tags=",".join([tag.name for tag in self.tags.all()]), suggestions={"input": [tag.name for tag in self.tags.all()]}, publish_date=self.publish_date) obj.save() return obj.to_dict(include_meta=True)
def bulk_indexing(cls): BlogPostIndex.init() bulk( client=es_client, actions=(b.indexing() for b in cls.objects.all().iterator()), )
def suggest_search(word): """ :return: """ res = BlogPostIndex.suggest_word(word) return res
def search_posts(words): """ :return: """ res = BlogPostIndex.search_posts(words) return res
def test_blogpost(): # 问题1 搜索Django没有搜索出来???? res = BlogPostIndex.search_posts("django") print(res) res = BlogPostIndex.suggest_word("数据") print(res)