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
钟尚武
physical
Commits
19d64d4d
Commit
19d64d4d
authored
May 17, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Plain Diff
去掉空画报
parents
6d7366dc
782c974f
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
224 additions
and
148 deletions
+224
-148
Project.xml
.idea/codeStyles/Project.xml
+0
-25
tasks.py
injection/data_sync/tasks.py
+11
-2
collect_data.py
linucb/views/collect_data.py
+22
-31
topic.py
search/utils/topic.py
+82
-42
group.py
search/views/group.py
+14
-1
topic.py
search/views/topic.py
+57
-31
topic-high-star.json
trans2es/mapping/topic-high-star.json
+1
-0
topic-star-routing.json
trans2es/mapping/topic-star-routing.json
+1
-0
topic.json
trans2es/mapping/topic.json
+1
-0
user.json
trans2es/mapping/user.json
+1
-0
tag.py
trans2es/models/tag.py
+2
-0
topic.py
trans2es/models/topic.py
+12
-16
user.py
trans2es/models/user.py
+14
-0
topic_transfer.py
trans2es/utils/topic_transfer.py
+5
-0
user_transfer.py
trans2es/utils/user_transfer.py
+1
-0
No files found.
.idea/codeStyles/Project.xml
View file @
19d64d4d
...
...
@@ -24,29 +24,5 @@
<option
name=
"ITERATION_ELEMENTS_WRAPPING"
value=
"chop_down_if_not_single"
/>
</formatting-settings>
</DBN-SQL>
<DBN-PSQL>
<case-options
enabled=
"false"
>
<option
name=
"KEYWORD_CASE"
value=
"lower"
/>
<option
name=
"FUNCTION_CASE"
value=
"lower"
/>
<option
name=
"PARAMETER_CASE"
value=
"lower"
/>
<option
name=
"DATATYPE_CASE"
value=
"lower"
/>
<option
name=
"OBJECT_CASE"
value=
"preserve"
/>
</case-options>
<formatting-settings
enabled=
"false"
/>
</DBN-PSQL>
<DBN-SQL>
<case-options
enabled=
"false"
>
<option
name=
"KEYWORD_CASE"
value=
"lower"
/>
<option
name=
"FUNCTION_CASE"
value=
"lower"
/>
<option
name=
"PARAMETER_CASE"
value=
"lower"
/>
<option
name=
"DATATYPE_CASE"
value=
"lower"
/>
<option
name=
"OBJECT_CASE"
value=
"preserve"
/>
</case-options>
<formatting-settings
enabled=
"false"
>
<option
name=
"STATEMENT_SPACING"
value=
"one_line"
/>
<option
name=
"CLAUSE_CHOP_DOWN"
value=
"chop_down_if_statement_long"
/>
<option
name=
"ITERATION_ELEMENTS_WRAPPING"
value=
"chop_down_if_not_single"
/>
</formatting-settings>
</DBN-SQL>
</code_scheme>
</component>
\ No newline at end of file
injection/data_sync/tasks.py
View file @
19d64d4d
...
...
@@ -60,12 +60,21 @@ def sync_face_similar_data_to_redis():
item_list
=
list
()
for
item
in
similar_result_items
:
weight_score
=
int
(
item
.
similarity
*
100
)
item_list
.
append
(
{
"contrast_user_id"
:
item
.
contrast_user_id
,
"similarity"
:
item
.
similarity
"filter"
:{
"constant_score"
:{
"filter"
:{
"term"
:{
"user_id"
:
item
.
contrast_user_id
}
}
}
},
"weight"
:
weight_score
*
2
}
)
if
len
(
item_list
)
>=
100
:
break
redis_client
.
set
(
redis_key
,
json
.
dumps
(
item_list
))
logging
.
info
(
"participant_user_id:
%
d set data done!"
%
participant_user_id
)
...
...
linucb/views/collect_data.py
View file @
19d64d4d
...
...
@@ -68,7 +68,6 @@ class CollectData(object):
if
len
(
recommend_tag_list
)
>
0
:
tag_recommend_redis_key
=
self
.
linucb_recommend_redis_prefix
+
str
(
device_id
)
redis_client
.
set
(
tag_recommend_redis_key
,
json
.
dumps
(
recommend_tag_list
))
# Todo:设置过期时间,调研set是否支持
redis_client
.
expire
(
tag_recommend_redis_key
,
7
*
24
*
60
*
60
)
have_read_topic_id_list
=
Tools
.
get_have_read_topic_id_list
(
device_id
,
user_id
,
TopicPageType
.
HOME_RECOMMEND
)
...
...
@@ -80,38 +79,35 @@ class CollectData(object):
recommend_topic_id_list_click
=
list
()
recommend_topic_id_list_click_dict
=
dict
()
if
click_topic_tag_list
:
if
len
(
click_topic_tag_list
)
>
0
:
recommend_topic_id_list_click
,
recommend_topic_id_list_click_dict
=
ESPerform
.
get_tag_topic_list_dict
(
click_topic_tag_list
,
if
click_topic_tag_list
and
len
(
click_topic_tag_list
)
>
0
:
recommend_topic_id_list_click
,
recommend_topic_id_list_click_dict
=
ESPerform
.
get_tag_topic_list_dict
(
click_topic_tag_list
,
have_read_topic_id_list
,
size
=
2
)
if
len
(
recommend_topic_id_list_click
)
>
0
:
recommend_topic_id_list
.
extend
(
recommend_topic_id_list_click
)
recommend_topic_id_list_dict
.
update
(
recommend_topic_id_list_click_dict
)
have_read_topic_id_list
.
extend
(
recommend_topic_id_list_click
)
click_recommend_redis_key
=
self
.
click_recommend_redis_key_prefix
+
str
(
device_id
)
click_redis_data_dict
=
{
"data"
:
json
.
dumps
(
recommend_topic_id_list
),
"datadict"
:
json
.
dumps
(
recommend_topic_id_list_dict
),
"cursor"
:
0
}
redis_client
.
hmset
(
click_recommend_redis_key
,
click_redis_data_dict
)
#
have_read_topic_id_list.extend(recommend_topic_id_list_click)
#
click_recommend_redis_key = self.click_recommend_redis_key_prefix + str(device_id)
#
click_redis_data_dict = {
#
"data": json.dumps(recommend_topic_id_list),
#
"datadict":json.dumps(recommend_topic_id_list_dict),
#
"cursor": 0
#
}
#
redis_client.hmset(click_recommend_redis_key, click_redis_data_dict)
tag_id_list
=
recommend_tag_list
[
0
:
100
]
topic_recommend_redis_key
=
self
.
linucb_recommend_topic_id_prefix
+
str
(
device_id
)
redis_topic_data_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
redis_topic_list
=
list
()
cursor
=
-
1
if
b
"data"
in
redis_topic_data_dict
:
redis_topic_list
=
json
.
loads
(
redis_topic_data_dict
[
b
"data"
])
if
redis_topic_data_dict
[
b
"data"
]
else
[]
cursor
=
int
(
str
(
redis_topic_data_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
if
len
(
recommend_topic_id_list
)
==
0
and
cursor
==
0
and
len
(
redis_topic_list
)
>
0
:
have_read_topic_id_list
.
extend
(
redis_topic_list
[:
2
])
tag_topic_dict
=
dict
()
# redis_topic_data_dict = redis_client.hgetall(topic_recommend_redis_key)
# redis_topic_list = list()
# cursor = -1
# if b"data" in redis_topic_data_dict:
# redis_topic_list = json.loads(redis_topic_data_dict[b"data"]) if redis_topic_data_dict[
# b"data"] else []
# cursor = int(str(redis_topic_data_dict[b"cursor"], encoding="utf-8"))
# if len(recommend_topic_id_list)==0 and cursor==0 and len(redis_topic_list)>0:
# have_read_topic_id_list.extend(redis_topic_list[:2])
if
len
(
new_user_click_tag_list
)
>
0
:
tag_topic_id_list
,
tag_topic_dict
=
ESPerform
.
get_tag_topic_list_dict
(
new_user_click_tag_list
,
have_read_topic_id_list
)
...
...
@@ -119,7 +115,7 @@ class CollectData(object):
tag_topic_id_list
,
tag_topic_dict
=
ESPerform
.
get_tag_topic_list_dict
(
tag_id_list
,
have_read_topic_id_list
)
if
len
(
recommend_topic_id_list
)
>
0
or
len
(
new_user_click_tag_list
)
>
0
:
if
len
(
recommend_topic_id_list
)
>
0
or
len
(
tag_topic_id_list
)
>
0
or
len
(
new_user_click_tag_list
)
>
0
:
tag_topic_id_list
=
recommend_topic_id_list
+
tag_topic_id_list
tag_topic_dict
.
update
(
recommend_topic_id_list_dict
)
redis_data_dict
=
{
...
...
@@ -128,11 +124,6 @@ class CollectData(object):
"cursor"
:
0
}
redis_client
.
hmset
(
topic_recommend_redis_key
,
redis_data_dict
)
else
:
if
cursor
<=
0
and
len
(
redis_topic_list
)
>
0
:
tag_topic_dict
=
list
()
tag_topic_dict
=
redis_topic_list
[:
2
]
tag_topic_dict
=
list
(
set
(
tag_topic_dict
))
return
True
except
:
...
...
search/utils/topic.py
View file @
19d64d4d
...
...
@@ -11,6 +11,8 @@ from libs.es import ESPerform
from
.common
import
TopicDocumentField
from
search.utils.common
import
*
from
trans2es.models.pictorial
import
PictorialTopics
from
libs.cache
import
redis_client
class
TopicUtils
(
object
):
...
...
@@ -33,7 +35,7 @@ class TopicUtils(object):
}
q
[
"_source"
]
=
{
"include"
:
[
"tag_list"
,
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_pictorial_user_id_list"
]
"include"
:
[
"tag_list"
,
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_pictorial_user_id_list"
]
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
,
size
)
...
...
@@ -139,14 +141,12 @@ class TopicUtils(object):
# pick_user_id_list = list()
# same_group_id_list = list()
user_tag_list
=
list
()
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
0
,
1
)
if
len
(
result_dict
[
"hits"
])
==
0
:
logging
.
warning
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
else
:
attention_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_user_id_list"
]
attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
attention_user_info_list
]
# pick_user_info_list = result_dict["hits"][0]["_source"]["pick_user_id_list"]
# pick_user_id_list = [item["user_id"] for item in pick_user_info_list]
...
...
@@ -161,14 +161,6 @@ class TopicUtils(object):
q
[
"query"
]
=
dict
()
functions_list
=
[
# {
# "filter": {
# "term": {
# "language_type": 1
# }
# },
# "weight": 60
# },
{
"gauss"
:
{
"create_time"
:
{
...
...
@@ -177,38 +169,22 @@ class TopicUtils(object):
}
},
"weight"
:
60
},
# {
# "filter": {
# "constant_score":{
# "filter":{
# "term": {
# "content_level": 6
# }
# }
# }
# },
# "weight": 600
# }
}
]
# if len(user_similar_score_list) > 0:
# for item in user_similar_score_list[:100]:
# score_item = 2 + item[1]
# functions_list.append(
# {
# "filter": {"bool": {
# "should": {"term": {"user_id": item[0]}}}},
# "weight": score_item,
# }
# )
if
user_id
and
user_id
>
0
:
redis_key_prefix
=
"physical:user_similar:participant_user_id:"
similar_redis_key
=
redis_key_prefix
+
str
(
user_id
)
redis_user_similar_data
=
redis_client
.
get
(
similar_redis_key
)
user_similar_list
=
json
.
loads
(
redis_user_similar_data
)
if
redis_user_similar_data
else
[]
if
len
(
user_similar_list
)
>
0
:
functions_list
.
extend
(
user_similar_list
)
if
len
(
attention_user_id_list
)
>
0
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"terms"
:
{
"user_id"
:
attention_user_id_list
}}}},
"weight"
:
30
,
"filter"
:
{
"constant_score"
:{
"filter"
:{
"terms"
:
{
"user_id"
:
attention_user_id_list
}}}},
"weight"
:
100
,
}
)
if
len
(
attention_tag_list
)
>
0
:
...
...
@@ -219,13 +195,10 @@ class TopicUtils(object):
"weight"
:
100
}
)
query_function_score
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[
# {"term": {"content_level": 6}},
# {"term": {"has_image":True}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}}
],
...
...
@@ -297,7 +270,7 @@ class TopicUtils(object):
]
query_function_score
[
"query"
][
"bool"
][
"minimum_should_match"
]
=
1
query_function_score
[
"query"
][
"bool"
][
"filter"
]
.
append
(
{
"range"
:
{
"content_level"
:
{
"gte"
:
4
,
"lte"
:
6
}}}
{
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
6
}}}
)
else
:
if
"must_not"
in
query_function_score
[
"query"
][
"bool"
]:
...
...
@@ -321,7 +294,6 @@ class TopicUtils(object):
q
[
"collapse"
]
=
{
"field"
:
"user_id"
}
# "includes": ["id", "pictorial_id", "offline_score", "user_id", "edit_tag_list"]
q
[
"_source"
]
=
{
"includes"
:
[
"id"
]
}
...
...
@@ -361,6 +333,74 @@ class TopicUtils(object):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
@classmethod
def
userful_tag_topic_list
(
cls
,
user_id
,
have_read_topic_list
,
size
,
index_type
=
"topic-high-star"
,
routing
=
None
):
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
:param topic_tag_list:
:param topic_group_id:
:param topic_user_id:
:param offset:
:param size:
:return:
"""
try
:
es_cli_obj
=
ESPerform
.
get_cli
()
useful_tag_list
=
list
()
q
=
dict
()
q
[
"query"
]
=
{
"term"
:
{
"user_id"
:
user_id
}
}
q
[
"_source"
]
=
{
"include"
:
[
"useful_tag_list"
]
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
0
,
1
)
if
len
(
result_dict
[
"hits"
])
==
0
:
logging
.
warning
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
else
:
useful_tag_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"useful_tag_list"
]
if
len
(
useful_tag_list
)
==
0
:
return
[]
else
:
q
=
dict
()
q
[
"query"
]
=
dict
()
# logging.warning("topic_tag_list:%s"%str(topic_tag_list))
query_function_score
=
{
"query"
:
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"terms"
:
{
"tag_list"
:
useful_tag_list
}}
],
"must_not"
:
{
"terms"
:
{
"id"
:
have_read_topic_list
}
}
}
}
}
q
[
"_source"
]
=
{
"includes"
:
[
"id"
]
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
size
=
size
,
routing
=
routing
)
topic_id_list
=
list
()
for
item
in
result_dict
[
"hits"
]:
topic_id_list
.
append
(
item
[
"_source"
][
"id"
])
return
topic_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
topic_tag_list
,
topic_pictorial_id
,
topic_user_id
,
filter_topic_user_id
,
have_read_topic_list
,
offset
,
size
,
es_cli_obj
=
None
,
...
...
search/views/group.py
View file @
19d64d4d
...
...
@@ -10,6 +10,7 @@ from libs.es import ESPerform
from
search.utils.group
import
GroupUtils
from
search.utils.common
import
GroupSortTypes
from
libs.es
import
ESPerform
from
trans2es.models.pictorial
import
PictorialTopics
@bind
(
"physical/search/query_pictorial"
)
...
...
@@ -217,7 +218,7 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
@bind
(
"physical/search/pictorial_topic_sort"
)
def
pictorial_topic_sort
(
pictorial_id
=-
1
,
offset
=
0
,
size
=
10
):
"""
:remark
小组排序,缺少:前1天发评论人数*x
:remark
画报排序 人气 部分
:param user_id:
:param sort_type:
:param offset:
...
...
@@ -249,13 +250,25 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
es_cli_obj
=
ESPerform
.
get_cli
()
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
offset
,
size
)
<<<<<<<
HEAD
logging
.
info
(
"get pictorial_topic_sort res:
%
s"
%
result_dict
)
=======
>>>>>>>
782
c974fb2bbb3a061ceb4440c72fe579b17ad26
for
item
in
result_dict
[
"hits"
]:
topic_id
=
item
[
"_source"
][
"id"
]
pict_pictorial_ids_list
.
append
(
topic_id
)
<<<<<<<
HEAD
return
{
"pict_pictorial_ids_list"
:
pict_pictorial_ids_list
}
=======
if
len
(
pict_pictorial_ids_list
)
==
0
and
offset
==
0
:
pict_pictorial_ids_list
=
list
(
PictorialTopics
.
objects
.
filter
(
pictorial_id
=
pictorial_id
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"topic_id"
,
flat
=
True
)[
offset
:
size
])
return
{
"pict_pictorial_ids_list"
:
pict_pictorial_ids_list
}
>>>>>>>
782
c974fb2bbb3a061ceb4440c72fe579b17ad26
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
search/views/topic.py
View file @
19d64d4d
...
...
@@ -46,16 +46,18 @@ def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageTy
def
get_home_recommend_topic_ids
(
user_id
,
device_id
,
tag_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
disable_collpase
=
False
):
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
disable_collpase
=
False
,
usefulrecall
=
-
1
):
try
:
topic_star_routing
=
"6"
index_type
=
"topic-high-star"
if
query
is
None
:
if
user_id
>
0
:
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":query_type:"
+
str
(
query_type
)
else
:
redis_key
=
"physical:home_recommend"
+
":device_id:"
+
device_id
+
":query_type:"
+
str
(
query_type
)
else
:
topic_star_routing
=
"4,5,6"
topic_star_routing
=
"3,4,5,6"
index_type
=
"topic"
if
user_id
>
0
:
redis_key
=
"physical:home_query"
+
":user_id:"
+
str
(
user_id
)
+
":query:"
+
str
(
query
)
+
":query_type:"
+
str
(
query_type
)
else
:
...
...
@@ -74,37 +76,47 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
else
:
if
offset
>
0
:
# 首次搜索时不需要过滤已读
have_read_topic_id_list
=
list
(
json
.
loads
(
redis_field_val_list
[
0
]))
# user_similar_score_redis_key = "physical:user_similar_score:user_id:" + str(user_id)
# redis_user_similar_score_redis_val = redis_client.get(user_similar_score_redis_key)
# user_similar_score_redis_list = json.loads(
# redis_user_similar_score_redis_val) if redis_user_similar_score_redis_val else []
have_read_topic_id_list
.
extend
(
promote_topic_list
)
useful_topic_id_list
=
list
()
recommend_topic_user_list
=
list
()
attention_tag_list
=
list
()
recommend_topic_list
=
list
()
if
query
is
None
:
if
user_id
!=
-
1
:
# 有用标签召回
if
usefulrecall
!=
-
1
:
useful_topic_id_list
=
TopicUtils
.
userful_tag_topic_list
(
user_id
,
have_read_topic_id_list
,
4
,
"topic-high-star"
,
"6"
)
# user_similar_score_redis_key = "physical:user_similar_score:user_id:" + str(user_id)
# redis_user_similar_score_redis_val = redis_client.get(user_similar_score_redis_key)
# user_similar_score_redis_list = json.loads(
# redis_user_similar_score_redis_val) if redis_user_similar_score_redis_val else []
size
=
size
-
len
(
useful_topic_id_list
)
have_read_topic_id_list
=
have_read_topic_id_list
.
extend
(
useful_topic_id_list
)
# linucb 推荐帖子
topic_recommend_redis_key
=
"physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
recommend_topic_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
linucb_recommend_topic_id_list
=
list
()
if
b
"data"
in
recommend_topic_dict
:
recommend_topic_id_list
=
json
.
loads
(
recommend_topic_dict
[
b
"data"
])
linucb_recommend_topic_id_list
=
json
.
loads
(
recommend_topic_dict
[
b
"data"
])
# 推荐帖子是强插的,要保证推荐帖子不在已读里
# recommend_topic_id_list = list(set(recommend_topic_id_list) - set(have_read_topic_id_list))
cursor
=
int
(
str
(
recommend_topic_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
newcursor
=
cursor
+
6
if
len
(
recommend_topic_id_list
)
>
newcursor
:
recommend_topic_list
=
recommend_topic_id_list
[
cursor
:
newcursor
]
redis_client
.
hset
(
topic_recommend_redis_key
,
"cursor"
,
newcursor
)
if
linucb_recommend_topic_id_list
!=
None
:
recommend_topic_id_list
=
list
(
set
(
linucb_recommend_topic_id_list
)
-
set
(
have_read_topic_id_list
))
recommend_topic_id_list
.
sort
(
key
=
linucb_recommend_topic_id_list
.
index
)
# cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
# newcursor = cursor + 6
if
len
(
recommend_topic_id_list
)
>
0
:
recommend_topic_list
=
recommend_topic_id_list
[
0
:
size
]
# redis_client.hset(topic_recommend_redis_key, "cursor", newcursor)
if
b
"datadict"
in
recommend_topic_dict
:
recommend_topic_id_dict
=
json
.
loads
(
recommend_topic_dict
[
b
"datadict"
])
if
l
en
(
recommend_topic_list
)
==
6
and
recommend_topic_id_dict
is
not
None
:
linucb_
recommend_topic_id_dict
=
json
.
loads
(
recommend_topic_dict
[
b
"datadict"
])
if
l
inucb_recommend_topic_id_dict
is
not
None
and
len
(
recommend_topic_list
)
>
0
:
for
i
in
recommend_topic_list
:
recommend_topic_user_list
.
append
(
recommend_topic_id_dict
[
str
(
i
)])
recommend_topic_user_list
.
append
(
linucb_
recommend_topic_id_dict
[
str
(
i
)])
# 用户关注标签
redis_tag_data
=
redis_client
.
hget
(
"physical:linucb:register_user_tag_info"
,
user_id
)
attention_tag_list
=
json
.
loads
(
redis_tag_data
)
if
redis_tag_data
else
[]
...
...
@@ -119,12 +131,12 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
#
# for topic_id in promote_recommend_topic_id_list:
# have_read_topic_id_list_add_promote.append(topic_id)
have_read_topic_id_list
.
extend
(
promote_topic_list
)
topic_id_list
=
list
()
rank_topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
=
user_id
,
tag_id
=
tag_id
,
offset
=
0
,
size
=
size
,
single_size
=
size
,
query
=
query
,
query_type
=
query_type
,
filter_topic_id_list
=
have_read_topic_id_list
,
index_type
=
"topic-high-star"
,
routing
=
topic_star_routing
,
attention_tag_list
=
attention_tag_list
,
linucb_user_id_list
=
recommend_topic_user_list
,
disable_collpase
=
disable_collpase
)
rank_topic_id_list
=
list
(
)
if
size
>
0
:
rank_topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
=
user_id
,
tag_id
=
tag_id
,
offset
=
0
,
size
=
size
,
single_size
=
size
,
query
=
query
,
query_type
=
query_type
,
filter_topic_id_list
=
have_read_topic_id_list
,
index_type
=
index_type
,
routing
=
topic_star_routing
,
attention_tag_list
=
attention_tag_list
,
linucb_user_id_list
=
recommend_topic_user_list
,
disable_collpase
=
disable_collpase
)
# if len(recommend_topic_list) == 6 and query is None:
# if (size < 11):
...
...
@@ -150,11 +162,16 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
redis_client
.
hmset
(
redis_key
,
redis_dict
)
# 每个session key保存60天
redis_client
.
expire
(
redis_key
,
60
*
60
*
24
*
60
)
return
recommend_topic_list
,
rank_topic_id_list
if
usefulrecall
!=
-
1
:
return
recommend_topic_list
,
rank_topic_id_list
,
useful_topic_id_list
else
:
return
recommend_topic_list
,
rank_topic_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[],[]
if
usefulrecall
!=
-
1
:
return
[],[],[]
else
:
return
[],
[]
@bind
(
"physical/search/query_tag_id_by_topic"
)
...
...
@@ -167,7 +184,7 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1):
@bind
(
"physical/search/home_recommend"
)
def
home_recommend
(
device_id
=
""
,
user_id
=-
1
,
offset
=
0
,
size
=
10
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[]):
def
home_recommend
(
device_id
=
""
,
user_id
=-
1
,
offset
=
0
,
size
=
10
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[]
,
usefulrecall
=
-
1
):
"""
:remark:首页推荐,目前只推荐日记
:param session_id:
...
...
@@ -184,6 +201,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, size=10, query_type=Topic
recommend_topic_ids
=
list
()
rank_topic_ids
=
list
()
useful_topic_ids
=
list
()
es_node_load_high_flag
=
False
# try:
# es_node_load_high_flag = ESPerform.if_es_node_load_high(ESPerform.get_cli())
...
...
@@ -204,13 +222,21 @@ def home_recommend(device_id="", user_id=-1, offset=0, size=10, query_type=Topic
recommend_topic_ids
=
have_read_topic_id_list
[
0
:
size
]
else
:
if
usefulrecall
!=
-
1
:
recommend_topic_ids
,
rank_topic_ids
,
useful_topic_ids
=
get_home_recommend_topic_ids
(
user_id
,
device_id
,
tag_id
=
0
,
offset
=
0
,
size
=
size
,
query_type
=
query_type
,
promote_topic_list
=
promote_topic_list
,
usefulrecall
=
usefulrecall
)
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
"useful_topic_ids"
:
useful_topic_ids
}
else
:
recommend_topic_ids
,
rank_topic_ids
=
get_home_recommend_topic_ids
(
user_id
,
device_id
,
tag_id
=
0
,
offset
=
0
,
size
=
size
,
query_type
=
query_type
,
promote_topic_list
=
promote_topic_list
)
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
}
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"linucb_topic_ids"
:
[],
"rank_topic_ids"
:[]}
if
usefulrecall
!=
-
1
:
return
{
"linucb_topic_ids"
:
[],
"rank_topic_ids"
:[],
"useful_topic_ids"
:[]}
else
:
return
{
"linucb_topic_ids"
:
[],
"rank_topic_ids"
:
[]}
@bind
(
"physical/search/discover_page"
)
...
...
trans2es/mapping/topic-high-star.json
View file @
19d64d4d
...
...
@@ -17,6 +17,7 @@
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"share_num"
:{
"type"
:
"long"
},
...
...
trans2es/mapping/topic-star-routing.json
View file @
19d64d4d
...
...
@@ -16,6 +16,7 @@
"user_nick_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
//帖子用户名
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
...
...
trans2es/mapping/topic.json
View file @
19d64d4d
...
...
@@ -17,6 +17,7 @@
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"share_num"
:{
"type"
:
"long"
},
...
...
trans2es/mapping/user.json
View file @
19d64d4d
...
...
@@ -9,6 +9,7 @@
"is_online"
:{
"type"
:
"boolean"
},
//是否上线
"is_deleted"
:{
"type"
:
"boolean"
},
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"city_id"
:{
"type"
:
"text"
},
"country_id"
:{
"type"
:
"text"
},
"is_recommend"
:{
"type"
:
"boolean"
},
//是否运营推荐用户
...
...
trans2es/models/tag.py
View file @
19d64d4d
...
...
@@ -20,6 +20,7 @@ class TopicTag(models.Model):
topic_id
=
models
.
IntegerField
(
verbose_name
=
u"帖子ID"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否在线"
)
is_collection
=
models
.
IntegerField
(
verbose_name
=
u"是否编辑标签"
)
is_body_esthetics
=
models
.
IntegerField
(
verbose_name
=
u"是否有用标签"
)
class
AccountUserTag
(
models
.
Model
):
...
...
@@ -33,6 +34,7 @@ class AccountUserTag(models.Model):
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
is_body_esthetics
=
models
.
IntegerField
(
verbose_name
=
u"是否有用标签"
)
class
Tag
(
models
.
Model
):
...
...
trans2es/models/topic.py
View file @
19d64d4d
...
...
@@ -191,6 +191,18 @@ class Topic(models.Model):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
([],[])
def
get_topic_useful_tag_id_list
(
self
):
try
:
topic_useful_tag_id_list
=
list
()
tag_id_list
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
self
.
id
,
is_online
=
True
,
is_body_esthetics
=
1
)
for
tag_item
in
tag_id_list
:
topic_useful_tag_id_list
.
append
(
tag_item
.
tag_id
)
return
topic_useful_tag_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_tag_name_list
(
self
,
tag_id_list
):
try
:
tag_name_list
=
list
()
...
...
@@ -227,10 +239,6 @@ class Topic(models.Model):
elif
user_query_results
[
0
]
.
is_shadow
:
user_is_shadow
=
True
# 是否官方推荐小组
# if self.group and self.group.is_recommend:
# offline_score += 4.0
# 帖子等级
if
self
.
content_level
==
'5'
:
offline_score
+=
100.0
*
3
...
...
@@ -239,20 +247,8 @@ class Topic(models.Model):
elif
self
.
content_level
==
'6'
:
offline_score
+=
200.0
*
3
# is_excellent = self.judge_if_excellent_topic(self.id)
# if is_excellent:
# offline_score += 200.0
if
self
.
language_type
==
1
:
offline_score
+=
60.0
# exposure_count = ActionSumAboutTopic.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=self.id, data_type=1).count()
# click_count = ActionSumAboutTopic.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=self.id, data_type=2).count()
# uv_num = ActionSumAboutTopic.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=self.id, data_type=3).count()
#
# if exposure_count > 0:
# offline_score += click_count / exposure_count
# if uv_num > 0:
# offline_score += (self.vote_num / uv_num + self.reply_num / uv_num)
"""
1:马甲账号是否对总分降权?
...
...
trans2es/models/user.py
View file @
19d64d4d
...
...
@@ -189,3 +189,16 @@ class User(models.Model):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_user_useful_tag_id_list
(
self
):
try
:
user_useful_tag_id_list
=
list
()
query_results
=
AccountUserTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user
=
self
.
user_id
,
is_body_esthetics
=
1
,
is_deleted
=
False
)
for
item
in
query_results
:
user_useful_tag_id_list
.
append
(
item
.
tag_id
)
return
user_useful_tag_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
\ No newline at end of file
trans2es/utils/topic_transfer.py
View file @
19d64d4d
...
...
@@ -75,6 +75,11 @@ class TopicTransfer(object):
end
=
time
.
time
()
time4
=
(
end
-
begin
)
# begin = time.time()
topic_useful_tag_id_list
=
instance
.
get_topic_useful_tag_id_list
()
res
[
"useful_tag_list"
]
=
topic_useful_tag_id_list
# end = time.time()
# time5 = (end - begin)
# # 片假名
# re_jp_pian_words = re.compile(u"[\u30a0-\u30ff]+")
# m_pian = re_jp_pian_words.search(instance.content, 0)
...
...
trans2es/utils/user_transfer.py
View file @
19d64d4d
...
...
@@ -73,6 +73,7 @@ class UserTransfer(object):
try
:
res
[
"tag_list"
]
=
instance
.
get_user_tag_id_list
()
res
[
"useful_tag_list"
]
=
instance
.
get_user_useful_tag_id_list
()
res
[
"attention_user_id_list"
]
=
cls
.
get_follow_user_id_list
(
userInstance
=
instance
)
# res["attention_group_id_list"] = instance.get_attention_group_id_list()
...
...
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