예제 #1
0
파일: models.py 프로젝트: wmjie/ksm
 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)
예제 #2
0
 def bulk_indexing(cls):
     BlogPostIndex.init()
     bulk(
         client=es_client,
         actions=(b.indexing() for b in cls.objects.all().iterator()),
     )
예제 #3
0
 def suggest_search(word):
     """
     :return:
     """
     res = BlogPostIndex.suggest_word(word)
     return res
예제 #4
0
 def search_posts(words):
     """
     :return:
     """
     res = BlogPostIndex.search_posts(words)
     return res
예제 #5
0
파일: test_models4es.py 프로젝트: wmjie/ksm
def test_blogpost():
    # 问题1 搜索Django没有搜索出来????
    res = BlogPostIndex.search_posts("django")
    print(res)
    res = BlogPostIndex.suggest_word("数据")
    print(res)