You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
__author__ = 'bobby'
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from elasticsearch_dsl import DocType, Date, Nested, Boolean, \
|
|
|
|
analyzer, InnerObjectWrapper, Completion, Keyword, Text, Integer
|
|
|
|
|
|
|
|
from elasticsearch_dsl.analysis import CustomAnalyzer as _CustomAnalyzer
|
|
|
|
|
|
|
|
from elasticsearch_dsl.connections import connections
|
|
|
|
|
|
|
|
connections.create_connection(hosts=["localhost"])
|
|
|
|
|
|
|
|
|
|
|
|
class CustomAnalyzer(_CustomAnalyzer):
|
|
|
|
def get_analysis_definition(self):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
ik_analyzer = CustomAnalyzer("ik_max_word", filter=["lowercase"])
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleType(DocType):
|
|
|
|
# 伯乐在线文章类型
|
|
|
|
suggest = Completion(analyzer=ik_analyzer)
|
|
|
|
title = Text(analyzer="ik_max_word")
|
|
|
|
create_date = Date()
|
|
|
|
url = Keyword()
|
|
|
|
url_object_id = Keyword()
|
|
|
|
front_image_url = Keyword()
|
|
|
|
front_image_path = Keyword()
|
|
|
|
praise_nums = Integer()
|
|
|
|
comment_nums = Integer()
|
|
|
|
fav_nums = Integer()
|
|
|
|
tags = Text(analyzer="ik_max_word")
|
|
|
|
content = Text(analyzer="ik_max_word")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
index = "jobbole"
|
|
|
|
doc_type = "article"
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
ArticleType.init()
|