Commit 15416a2f authored by 段英荣's avatar 段英荣

Merge branch 'dlis' into 'master'

add

See merge request alpha/physical!117
parents ca25c64a cdf3d891
......@@ -14,5 +14,6 @@
<element value="search.views.user"/>
<element value="search.views.tag"/>
<element value="injection.data_sync.tasks"/>
<element value="search.views.contrast_similar"/>
</config>
</gm_rpcd_config>
# -*- coding: UTF-8 -*-
# !/usr/bin/env python
from __future__ import unicode_literals, absolute_import, print_function
from gm_rpcd.all import bind
import logging
import traceback
import json
from search.utils.topic import TopicUtils
from libs.es import ESPerform
from libs.cache import redis_client
from search.utils.common import *
from gm_rpcd.all import bind
import functools
import logging
import traceback
from libs.es import ESPerform
logger = logging.getLogger(__name__)
MAX_LOAD = 100
GROUP_SIZE = 10
@bind('physical/search/query_contrast_similar')
def contrast_similar(user_id, offset=0, size=10):
try:
if isinstance(user_id, int):
contrast_topic_id_list = get_all_topic_id_list(user_id, offset, size)
return {"contrast_similar_topic_id": contrast_topic_id_list}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"contrast_similar_topic_id": []}
def get_all_topic_id_list(user_id, offset, size):
try:
if user_id:
redis_key = "physical:user_similar:participant_user_id:" + str(user_id)
redis_field_val_list = redis_client.get(redis_key)
have_read_topic_id_list = json.loads(redis_field_val_list) if redis_field_val_list else []
read_topic_id_list = list()
if len(have_read_topic_id_list) > 0:
for i in have_read_topic_id_list:
read_topic_id_list.append(i.get("contrast_user_id"))
q = {
"query": {
"function_score": {
"query": {
"bool": {
"must": [{
"term": {
"is_online": True
}
}, {
"term": {
"is_deleted": False
}
},
{
"terms": {
"content_level": [3, 4, 5]
}
}],
"minimum_should_match": 1,
"should": {
"terms": {
"user_id": read_topic_id_list
}
}
}
}
}
}
}
logging.info('contrast_similar,as q:%s' % str(q).encode('utf-8'))
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="topic",
query_body=q,
offset=offset, size=size)
contrast_topic_ids = []
if len(result_dict['hits']) > 0:
res_hit = result_dict['hits']
for item in res_hit:
topic_id = item['_source']['id']
contrast_topic_ids.append(topic_id)
logging.info('contrast_similar_topic_id:%s' % contrast_topic_ids)
return contrast_topic_ids
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"contrast_similar_topic_id": []}
......@@ -73,8 +73,8 @@ class SyncDataToRedis(object):
redis_key = redis_key_prefix + str(participant_user_id)
similar_result_items = FaceUserContrastSimilar.objects.filter(is_online=True, is_deleted=False,
participant_user_id=participant_user_id,
similarity__gt=0.4).order_by(
"-similarity").limit(100)
similarity__gt=0.3).order_by(
"-similarity")
item_list = list()
for item in similar_result_items:
......
......@@ -105,18 +105,36 @@ class Topic(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_tag_name_list(self,tag_id_list):
def get_tag_name_list(self, tag_id_list):
try:
tag_name_list = list()
query_results = Tag.objects.filter(id__in=tag_id_list).values_list("name",flat=True)
for item in query_results:
tag_name_list.append(item)
logging.info("get tag_id_list :%s"%tag_id_list)
if len(tag_id_list) > 100:
lens = int(len(tag_id_list) / 100)
for i in range(lens+1):
if i != 0:
tag_id_100 = tag_id_list[i * 100:i * 100 + 100]
if i == 0:
tag_id_100 = tag_id_list[i:i + 100]
if i * 100 == lens * 100 and len(tag_id_list[lens * 100:]) > 0:
tag_id_100 = tag_id_list[lens * 100:]
if tag_id_100:
logging.info("get tag_id_100 :%s" % tag_id_100)
query_results = Tag.objects.filter(id__in=tag_id_100).values_list("name", flat=True)
for item in query_results:
tag_name_list.append(item)
else:
query_results = Tag.objects.filter(id__in=tag_id_list).values_list("name", flat=True)
for item in query_results:
tag_name_list.append(item)
return tag_name_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_topic_offline_score(self):
try:
offline_score = 0.0
......
This diff is collapsed.
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