Commit 7d8a861b authored by 段英荣's avatar 段英荣

modify

parent 14958d22
......@@ -25,12 +25,23 @@ def query_tag(query,offset,size):
try:
q = {
"query":{
"match":{
"name":query
"bool":{
"must":{
"is_online":True,
"is_deleted":False
},
"should":[
{"match":{"name": query}}
],
"minimum_should_match":1
}
},
"_source":{
"include":["id","name"]
"sort":[
{"near_new_topic_num":{"order":"desc"}},
{'_score': {"order": "desc"}}
],
"_source": {
"include": ["id", "name"]
}
}
q["highlight"] = get_highlight(["name"])
......
......@@ -3,6 +3,9 @@
"properties": {
"id":{"type":"long"},
"suggest":{"type":"completion"},
"name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"standard"}
"name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"standard"},
"is_online":{"type":"boolean"},//上线
"is_deleted":{"type":"boolean"},
"near_new_topic_num":{"type":"long"}
}
}
\ No newline at end of file
......@@ -42,6 +42,7 @@ class Tag(models.Model):
id = models.IntegerField(primary_key=True,verbose_name=u"主键ID")
is_deleted = models.BooleanField(verbose_name=u"是否删除")
is_online = models.BooleanField(verbose_name=u"是否上线")
name = models.CharField(verbose_name=u"标签名称",max_length=128)
description = models.TextField(verbose_name=u"标签描述")
icon_url=models.CharField(verbose_name=u"icon_url",max_length=120)
......
......@@ -5,6 +5,9 @@ import sys
import logging
import traceback
from libs.tools import tzlc
from trans2es.models.topic import Topic
from trans2es.models.tag import TopicTag
import datetime
class TagTransfer(object):
......@@ -16,6 +19,21 @@ class TagTransfer(object):
res["id"] = instance.id
res["suggest"] = instance.name
res["name"] = instance.name
res["is_online"] = instance.is_online
res["is_deleted"] = instance.is_deleted
res["near_new_topic_num"] = 0
if instance.is_online==True and instance.is_deleted==False:
topic_id_list = list()
sql_result_list = TopicTag.objects.filter(tag_id=instance.id,is_online=True).values_list("topic_id",flat=True)
for item_id in sql_result_list:
topic_id_list.append(item_id)
time_base_val = datetime.datetime.strftime(datetime.datetime.now()+datetime.timedelta(-7), "%Y-%m-%d")
topic_num = Topic.objects.filter(id__in=topic_id_list,is_online=True,is_deleted=False,create_time__gte=time_base_val).count()
res["near_new_topic_num"] = topic_num
return res
except:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment