Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
physical
Commits
076eb1c3
Commit
076eb1c3
authored
Dec 03, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
0f35bf68
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
85 additions
and
72 deletions
+85
-72
cache.py
libs/cache.py
+3
-0
error.py
libs/error.py
+3
-0
table_scan.py
libs/table_scan.py
+2
-1
django_init.py
physical/django_init.py
+3
-0
log_settings.py
physical/log_settings.py
+2
-4
topic.py
search/utils/topic.py
+31
-36
topic.py
search/views/topic.py
+41
-30
user.py
search/views/user.py
+0
-1
No files found.
libs/cache.py
View file @
076eb1c3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
redis
import
redis
from
django.conf
import
settings
from
django.conf
import
settings
...
...
libs/error.py
View file @
076eb1c3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
gm_rpcd.all
import
RPCDFaultException
from
gm_rpcd.all
import
RPCDFaultException
from
gm_types.doris.error
import
ERROR
from
gm_types.doris.error
import
ERROR
from
raven.contrib.django.raven_compat.models
import
client
as
_sentry_client
from
raven.contrib.django.raven_compat.models
import
client
as
_sentry_client
...
...
libs/table_scan.py
View file @
076eb1c3
# coding=utf-8
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
,
print_function
,
absolute_import
from
__future__
import
unicode_literals
,
print_function
,
absolute_import
import
six
import
six
...
...
physical/django_init.py
View file @
076eb1c3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
os
import
os
import
django
import
django
...
...
physical/log_settings.py
View file @
076eb1c3
# coding=utf-8
#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
__author__ = 'xumingming'
"""
import
os
import
os
...
...
search/utils/topic.py
View file @
076eb1c3
...
@@ -88,7 +88,7 @@ class TopicUtils(object):
...
@@ -88,7 +88,7 @@ class TopicUtils(object):
return
[]
return
[]
@classmethod
@classmethod
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
is_first_time
,
group_topic_ids_index
,
not_group_topic_ids_index
,
query
=
None
):
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
is_first_time
,
query
=
None
):
"""
"""
:需增加打散逻辑
:需增加打散逻辑
:remark:获取首页推荐帖子列表
:remark:获取首页推荐帖子列表
...
@@ -96,48 +96,40 @@ class TopicUtils(object):
...
@@ -96,48 +96,40 @@ class TopicUtils(object):
:param offset:
:param offset:
:param size:
:param size:
:param is_first_time:
:param is_first_time:
:param group_topic_ids_index:
:param not_group_topic_ids_index:
:return:
:return:
"""
"""
try
:
try
:
#重写offset,size
attention_user_id_term_list
=
list
()
size
=
1000
pick_user_id_term_list
=
list
()
if
is_first_time
:
same_group_user_id_term_list
=
list
()
offset
=
0
user_tag_list
=
list
()
else
:
if
group_topic_ids_index
>
0
:
offset
=
1000
*
group_topic_ids_index
else
:
offset
=
1000
*
not_group_topic_ids_index
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
0
,
1
)
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
0
,
1
)
if
len
(
result_dict
[
"hits"
])
==
0
:
if
len
(
result_dict
[
"hits"
])
==
0
:
logging
.
error
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
logging
.
warning
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
return
([],[])
else
:
attention_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_user_id_list"
]
(
attention_chinese_user_id_list
,
attention_japan_user_id_list
,
attention_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
related_user_id_list
=
attention_user_info_list
)
logging
.
info
(
"duan add,result_dict:
%
s"
%
str
(
result_dict
)
.
encode
(
"utf-8"
))
pick_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"pick_user_id_list"
]
attention_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_user_id_list"
]
(
pick_chinese_user_id_list
,
pick_japan_user_id_list
,
(
attention_chinese_user_id_list
,
attention_japan_user_id_list
,
pick_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
pick_user_info_list
)
attention_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
related_user_id_list
=
attention_user_info_list
)
pick_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"pick
_user_id_list"
]
same_group_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"same_group
_user_id_list"
]
(
pick_chinese_user_id_list
,
pick
_japan_user_id_list
,
(
same_group_chinese_user_id_list
,
same_group
_japan_user_id_list
,
pick_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
pick
_user_info_list
)
same_group_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
same_group
_user_info_list
)
same_group_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"same_group_user_id_list"
]
user_tag_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"tag_list"
]
(
same_group_chinese_user_id_list
,
same_group_japan_user_id_list
,
same_group_korea_user_id_list
)
=
TopicUtils
.
analyze_related_user_id_list
(
same_group_user_info_list
)
user_tag_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"tag_list"
]
attention_user_id_term_list
=
cls
.
___get_should_term_list
(
attention_chinese_user_id_list
+
attention_japan_user_id_list
+
attention_korea_user_id_list
)
pick_user_id_term_list
=
cls
.
___get_should_term_list
(
pick_chinese_user_id_list
+
pick_japan_user_id_list
+
pick_korea_user_id_list
)
same_group_user_id_term_list
=
cls
.
___get_should_term_list
(
same_group_chinese_user_id_list
+
same_group_japan_user_id_list
+
same_group_korea_user_id_list
)
q
=
dict
()
q
=
dict
()
q
[
"query"
]
=
dict
()
q
[
"query"
]
=
dict
()
attention_user_id_term_list
=
cls
.
___get_should_term_list
(
attention_chinese_user_id_list
+
attention_japan_user_id_list
+
attention_korea_user_id_list
)
pick_user_id_term_list
=
cls
.
___get_should_term_list
(
pick_chinese_user_id_list
+
pick_japan_user_id_list
+
pick_korea_user_id_list
)
same_group_user_id_term_list
=
cls
.
___get_should_term_list
(
same_group_chinese_user_id_list
+
same_group_japan_user_id_list
+
same_group_korea_user_id_list
)
functions_list
=
[
functions_list
=
[
{
{
"filter"
:
{
"bool"
:
{
"filter"
:
{
"bool"
:
{
...
@@ -212,25 +204,28 @@ class TopicUtils(object):
...
@@ -212,25 +204,28 @@ class TopicUtils(object):
logging
.
info
(
"duan add,es query:
%
s"
%
str
(
q
)
.
encode
(
"utf-8"
))
logging
.
info
(
"duan add,es query:
%
s"
%
str
(
q
)
.
encode
(
"utf-8"
))
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
offset
=
offset
,
size
=
size
)
group_topic_ids
=
list
()
not_group_topic_ids
=
list
()
"""
"""
group_topic_ids = list()
not_group_topic_ids = list()
q["filter"] = {
q["filter"] = {
"range": {"content_level": {"gte": 3, "lte": 5}}
"range": {"content_level": {"gte": 3, "lte": 5}}
}
}
"""
for item in result_dict["hits"]:
for item in result_dict["hits"]:
if item["_source"]["group_id"] and item["_source"]["group_id"]> 0:
if item["_source"]["group_id"] and item["_source"]["group_id"]> 0:
group_topic_ids.append(item["_source"]["id"])
group_topic_ids.append(item["_source"]["id"])
else:
else:
not_group_topic_ids.append(item["_source"]["id"])
not_group_topic_ids.append(item["_source"]["id"])
return
(
group_topic_ids
,
not_group_topic_ids
)
"""
if
len
(
result_dict
[
"hits"
])
>
0
:
return
[
item
[
"_source"
]
for
item
in
result_dict
[
"hits"
]]
else
:
return
[]
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
([],[])
return
[]
@classmethod
@classmethod
def
get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_tag_list
,
topic_group_id
,
topic_user_id
,
offset
,
size
):
def
get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_tag_list
,
topic_group_id
,
topic_user_id
,
offset
,
size
):
...
...
search/views/topic.py
View file @
076eb1c3
...
@@ -11,44 +11,53 @@ from libs.cache import redis_client
...
@@ -11,44 +11,53 @@ from libs.cache import redis_client
@bind
(
"physical/search/home_recommend"
)
@bind
(
"physical/search/home_recommend"
)
def
home_recommend
(
user_id
=-
1
,
offset
=
0
,
size
=
10
):
def
home_recommend
(
ctx
,
user_id
=-
1
,
offset
=
0
,
size
=
10
):
"""
"""
:remark:首页推荐,目前只推荐日记,缺少小组打散策略
:remark:首页推荐,目前只推荐日记,缺少小组打散策略
:return:
:return:
"""
"""
try
:
try
:
logging
.
info
(
"duan add,ctx:
%
s"
%
str
(
ctx
))
if
not
user_id
:
if
not
user_id
:
user_id
=-
1
user_id
=-
1
redis_key
=
"physical:home_recommend:"
+
"user_id:"
+
str
(
user_id
)
redis_key
=
"physical:home_recommend:"
+
"user_id:"
+
str
(
user_id
)
redis_val_dict
=
redis_client
.
hgetall
(
redis_key
)
redis_val_dict
=
redis_client
.
hgetall
(
redis_key
)
if
len
(
redis_val_dict
)
>
0
:
#if len(redis_val_dict) > 0:
group_topic_ids
=
json
.
loads
(
redis_val_dict
[
b
"group_topic_ids"
])
"""
not_group_topic_ids
=
json
.
loads
(
redis_val_dict
[
b
"not_group_topic_ids"
])
group_topic_ids = json.loads(redis_val_dict[b"group_topic_ids"])
group_topic_ids_index
=
int
(
redis_val_dict
[
b
"group_topic_ids_index"
])
not_group_topic_ids = json.loads(redis_val_dict[b"not_group_topic_ids"])
not_group_topic_ids_index
=
int
(
redis_val_dict
[
b
"not_group_topic_ids_index"
])
group_topic_ids_index = int(redis_val_dict[b"group_topic_ids_index"])
not_group_topic_ids_index = int(redis_val_dict[b"not_group_topic_ids_index"])
if
len
(
group_topic_ids
)
<
(
size
-
1
)
or
len
(
not_group_topic_ids
)
<
1
:
if len(group_topic_ids) < (size-1) or len(not_group_topic_ids) < 1:
if
len
(
group_topic_ids
)
<
(
size
-
1
):
if len(group_topic_ids) < (size-1):
group_topic_ids_index
+=
1
group_topic_ids_index += 1
(
new_group_topic_ids
,
new_not_group_topic_ids
)
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
,
(new_group_topic_ids, new_not_group_topic_ids) = TopicUtils.get_recommend_topic_ids(user_id, offset, size,
False
,
group_topic_ids_index
,
not_group_topic_ids_index
)
False, group_topic_ids_index, not_group_topic_ids_index)
group_topic_ids
+=
new_group_topic_ids
group_topic_ids += new_group_topic_ids
else
:
else:
not_group_topic_ids_index
+=
1
not_group_topic_ids_index += 1
(
new_group_topic_ids
,
new_not_group_topic_ids
)
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
,
(new_group_topic_ids, new_not_group_topic_ids) = TopicUtils.get_recommend_topic_ids(user_id, offset, size,
False
,
group_topic_ids_index
,
not_group_topic_ids_index
)
False, group_topic_ids_index, not_group_topic_ids_index)
not_group_topic_ids
+=
new_not_group_topic_ids
not_group_topic_ids += new_not_group_topic_ids
recommend_topic_ids
=
group_topic_ids
[:(
size
-
1
)]
+
not_group_topic_ids
[:
1
]
"""
redis_hash_dict
=
{
have_read_topic_ids_list
=
json
.
loads
(
redis_val_dict
[
b
"have_read_topic_ids"
])
"group_topic_ids"
:
group_topic_ids
[(
size
-
1
):],
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
,
False
)
"not_group_topic_ids"
:
not_group_topic_ids
[
1
:],
"group_topic_ids_index"
:
group_topic_ids_index
,
"""
"not_group_topic_ids_index"
:
not_group_topic_ids_index
recommend_topic_ids = group_topic_ids[:(size-1)] + not_group_topic_ids[:1]
}
redis_hash_dict = {
TopicUtils
.
refresh_redis_hash_data
(
redis_client
,
redis_key
,
redis_hash_dict
)
"group_topic_ids": group_topic_ids[(size-1):],
"not_group_topic_ids": not_group_topic_ids[1:],
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
"group_topic_ids_index":group_topic_ids_index,
"not_group_topic_ids_index":not_group_topic_ids_index
}
TopicUtils.refresh_redis_hash_data(redis_client,redis_key,redis_hash_dict)
"""
recommend_topic_ids
=
[
item
[
"id"
]
for
item
in
topic_id_list
]
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
"""
else:
else:
(group_topic_ids,not_group_topic_ids) = TopicUtils.get_recommend_topic_ids(user_id,offset,size,True,0,0)
(group_topic_ids,not_group_topic_ids) = TopicUtils.get_recommend_topic_ids(user_id,offset,size,True,0,0)
recommend_topic_ids = group_topic_ids[:(size - 1)] + not_group_topic_ids[:1]
recommend_topic_ids = group_topic_ids[:(size - 1)] + not_group_topic_ids[:1]
...
@@ -60,7 +69,9 @@ def home_recommend(user_id=-1,offset=0,size=10):
...
@@ -60,7 +69,9 @@ def home_recommend(user_id=-1,offset=0,size=10):
}
}
TopicUtils.refresh_redis_hash_data(redis_client, redis_key, redis_hash_dict)
TopicUtils.refresh_redis_hash_data(redis_client, redis_key, redis_hash_dict)
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
return {"recommend_topic_ids": recommend_topic_ids}
"""
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"recommend_topic_ids"
:
[]}
return
{
"recommend_topic_ids"
:
[]}
...
...
search/views/user.py
View file @
076eb1c3
...
@@ -11,7 +11,6 @@ from libs.cache import redis_client
...
@@ -11,7 +11,6 @@ from libs.cache import redis_client
from
search.utils.user
import
UserUtils
from
search.utils.user
import
UserUtils
@bind
(
"physical/search/recommend_user"
)
@bind
(
"physical/search/recommend_user"
)
def
recommend_user
(
user_id
=-
1
,
offset
=
0
,
size
=
10
):
def
recommend_user
(
user_id
=-
1
,
offset
=
0
,
size
=
10
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment