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
6a2b1cfe
Commit
6a2b1cfe
authored
May 16, 2019
by
Kai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
e30c5c30
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
52 additions
and
16 deletions
+52
-16
topic.py
search/utils/topic.py
+12
-5
topic.py
search/views/topic.py
+14
-5
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
+1
-0
topic.py
trans2es/models/topic.py
+1
-1
user.py
trans2es/models/user.py
+14
-0
topic_transfer.py
trans2es/utils/topic_transfer.py
+5
-5
user_transfer.py
trans2es/utils/user_transfer.py
+1
-0
No files found.
search/utils/topic.py
View file @
6a2b1cfe
...
@@ -33,7 +33,7 @@ class TopicUtils(object):
...
@@ -33,7 +33,7 @@ class TopicUtils(object):
}
}
q
[
"_source"
]
=
{
q
[
"_source"
]
=
{
"include"
:
[
"tag_list"
,
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_pictorial_user_id_list"
]
"include"
:
[
"tag_list"
,
"useful_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
)
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
,
size
)
...
@@ -125,7 +125,7 @@ class TopicUtils(object):
...
@@ -125,7 +125,7 @@ class TopicUtils(object):
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
filter_topic_id_list
=
[],
test_score
=
False
,
must_topic_id_list
=
[],
recommend_tag_list
=
[],
filter_topic_id_list
=
[],
test_score
=
False
,
must_topic_id_list
=
[],
recommend_tag_list
=
[],
user_similar_score_list
=
[],
index_type
=
"topic"
,
routing
=
None
,
attention_tag_list
=
[],
user_similar_score_list
=
[],
index_type
=
"topic"
,
routing
=
None
,
attention_tag_list
=
[],
linucb_user_id_list
=
[],
disable_collpase
=
False
):
linucb_user_id_list
=
[],
disable_collpase
=
False
,
usefulrecall
=
-
1
):
"""
"""
:remark:获取首页推荐帖子列表
:remark:获取首页推荐帖子列表
:param user_id:
:param user_id:
...
@@ -139,14 +139,14 @@ class TopicUtils(object):
...
@@ -139,14 +139,14 @@ class TopicUtils(object):
# pick_user_id_list = list()
# pick_user_id_list = list()
# same_group_id_list = list()
# same_group_id_list = list()
user_tag_list
=
list
()
user_tag_list
=
list
()
useful_tag_id_list
=
list
()
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
.
warning
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
logging
.
warning
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
else
:
else
:
attention_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_user_id_list"
]
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
]
attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
attention_user_info_list
]
useful_tag_id_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"useful_tag_list"
]
# pick_user_info_list = result_dict["hits"][0]["_source"]["pick_user_id_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]
# pick_user_id_list = [item["user_id"] for item in pick_user_info_list]
...
@@ -219,7 +219,14 @@ class TopicUtils(object):
...
@@ -219,7 +219,14 @@ class TopicUtils(object):
"weight"
:
100
"weight"
:
100
}
}
)
)
if
len
(
useful_tag_id_list
)
>
0
and
usefulrecall
!=
-
1
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"must"
:
{
"terms"
:
{
"tag_list"
:
useful_tag_id_list
}}}},
"weight"
:
100
}
)
query_function_score
=
{
query_function_score
=
{
"query"
:
{
"query"
:
{
"bool"
:
{
"bool"
:
{
...
...
search/views/topic.py
View file @
6a2b1cfe
...
@@ -80,10 +80,19 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
...
@@ -80,10 +80,19 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
# user_similar_score_redis_list = json.loads(
# user_similar_score_redis_list = json.loads(
# redis_user_similar_score_redis_val) if redis_user_similar_score_redis_val else []
# redis_user_similar_score_redis_val) if redis_user_similar_score_redis_val else []
recommend_topic_user_list
=
list
()
recommend_topic_user_list
=
list
()
useful_topic_id_list
=
list
()
attention_tag_list
=
list
()
attention_tag_list
=
list
()
recommend_topic_list
=
list
()
recommend_topic_list
=
list
()
if
query
is
None
:
if
query
is
None
:
#有用标签召回
useful_topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
=
user_id
,
tag_id
=
tag_id
,
offset
=
0
,
size
=
4
,
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
,
disable_collpase
=
disable_collpase
,
usefulrecall
=
1
)
# linucb 推荐帖子
# linucb 推荐帖子
topic_recommend_redis_key
=
"physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
topic_recommend_redis_key
=
"physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
...
@@ -96,20 +105,20 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
...
@@ -96,20 +105,20 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
recommend_topic_id_list
.
sort
(
key
=
linucb_recommend_topic_id_list
.
index
)
recommend_topic_id_list
.
sort
(
key
=
linucb_recommend_topic_id_list
.
index
)
# cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
# cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
# newcursor = cursor + 6
# newcursor = cursor + 6
if
len
(
recommend_topic_id_list
)
>
6
:
#
if len(recommend_topic_id_list) > 6:
recommend_topic_list
=
recommend_topic_id_list
[
0
:
6
]
recommend_topic_list
=
recommend_topic_id_list
[
0
:
8
]
# redis_client.hset(topic_recommend_redis_key, "cursor", newcursor)
# redis_client.hset(topic_recommend_redis_key, "cursor", newcursor)
if
b
"datadict"
in
recommend_topic_dict
:
if
b
"datadict"
in
recommend_topic_dict
:
linucb_recommend_topic_id_dict
=
json
.
loads
(
recommend_topic_dict
[
b
"datadict"
])
linucb_recommend_topic_id_dict
=
json
.
loads
(
recommend_topic_dict
[
b
"datadict"
])
if
len
(
recommend_topic_list
)
==
6
and
linucb_recommend_topic_id_dict
is
not
None
:
if
len
(
recommend_topic_list
)
>
0
and
linucb_recommend_topic_id_dict
is
not
None
:
for
i
in
recommend_topic_list
:
for
i
in
recommend_topic_list
:
recommend_topic_user_list
.
append
(
linucb_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
)
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
[]
attention_tag_list
=
json
.
loads
(
redis_tag_data
)
if
redis_tag_data
else
[]
if
len
(
recommend_topic_list
)
>
0
:
if
len
(
recommend_topic_list
)
>
0
:
size
=
size
-
len
(
recommend_topic_list
)
size
=
size
-
len
(
recommend_topic_list
)
-
len
(
useful_topic_id_list
)
have_read_topic_id_list
.
extend
(
recommend_topic_list
)
have_read_topic_id_list
.
extend
(
recommend_topic_list
)
# have_read_topic_id_list_add_promote = list()
# have_read_topic_id_list_add_promote = list()
...
...
trans2es/mapping/topic-high-star.json
View file @
6a2b1cfe
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"share_num"
:{
"type"
:
"long"
},
"share_num"
:{
"type"
:
"long"
},
...
...
trans2es/mapping/topic-star-routing.json
View file @
6a2b1cfe
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
"user_nick_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
//帖子用户名
"user_nick_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
//帖子用户名
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
...
...
trans2es/mapping/topic.json
View file @
6a2b1cfe
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"user_nick_name_pre"
:
{
"type"
:
"text"
,
"analyzer"
:
"keyword"
},
//不切词的用户名
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"group_id"
:{
"type"
:
"long"
},
//所在组ID
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"edit_tag_list"
:{
"type"
:
"long"
},
//编辑标签
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"share_num"
:{
"type"
:
"long"
},
"share_num"
:{
"type"
:
"long"
},
...
...
trans2es/mapping/user.json
View file @
6a2b1cfe
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
"is_online"
:{
"type"
:
"boolean"
},
//是否上线
"is_online"
:{
"type"
:
"boolean"
},
//是否上线
"is_deleted"
:{
"type"
:
"boolean"
},
"is_deleted"
:{
"type"
:
"boolean"
},
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"tag_list"
:{
"type"
:
"long"
},
//标签属性
"useful_tag_list"
:{
"type"
:
"long"
},
//有用标签属性
"city_id"
:{
"type"
:
"text"
},
"city_id"
:{
"type"
:
"text"
},
"country_id"
:{
"type"
:
"text"
},
"country_id"
:{
"type"
:
"text"
},
"is_recommend"
:{
"type"
:
"boolean"
},
//是否运营推荐用户
"is_recommend"
:{
"type"
:
"boolean"
},
//是否运营推荐用户
...
...
trans2es/models/tag.py
View file @
6a2b1cfe
...
@@ -34,6 +34,7 @@ class AccountUserTag(models.Model):
...
@@ -34,6 +34,7 @@ class AccountUserTag(models.Model):
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_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
):
class
Tag
(
models
.
Model
):
...
...
trans2es/models/topic.py
View file @
6a2b1cfe
...
@@ -199,7 +199,7 @@ class Topic(models.Model):
...
@@ -199,7 +199,7 @@ class Topic(models.Model):
for
tag_item
in
tag_id_list
:
for
tag_item
in
tag_id_list
:
is_online
=
tag_item
.
is_online
is_online
=
tag_item
.
is_online
is_body_esthetics
=
tag_item
.
is_body_esthetics
is_body_esthetics
=
tag_item
.
is_body_esthetics
if
is_online
and
is_body_esthetics
:
if
is_online
and
is_body_esthetics
!=
0
:
topic_useful_tag_id_list
.
append
(
tag_item
.
tag_id
)
topic_useful_tag_id_list
.
append
(
tag_item
.
tag_id
)
return
topic_useful_tag_id_list
return
topic_useful_tag_id_list
except
:
except
:
...
...
trans2es/models/user.py
View file @
6a2b1cfe
...
@@ -189,3 +189,16 @@ class User(models.Model):
...
@@ -189,3 +189,16 @@ class User(models.Model):
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
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 @
6a2b1cfe
...
@@ -75,11 +75,11 @@ class TopicTransfer(object):
...
@@ -75,11 +75,11 @@ class TopicTransfer(object):
end
=
time
.
time
()
end
=
time
.
time
()
time4
=
(
end
-
begin
)
time4
=
(
end
-
begin
)
begin
=
time
.
time
()
#
begin = time.time()
topic_
tag_id_list
=
instance
.
is_recommend
()
topic_
useful_tag_id_list
=
instance
.
get_topic_useful_tag_id_list
()
res
[
"useful_tag_list"
]
=
topic_tag_id_list
res
[
"useful_tag_list"
]
=
topic_
useful_
tag_id_list
end
=
time
.
time
()
#
end = time.time()
time1
=
(
end
-
begin
)
# time5
= (end - begin)
# # 片假名
# # 片假名
# re_jp_pian_words = re.compile(u"[\u30a0-\u30ff]+")
# re_jp_pian_words = re.compile(u"[\u30a0-\u30ff]+")
# m_pian = re_jp_pian_words.search(instance.content, 0)
# m_pian = re_jp_pian_words.search(instance.content, 0)
...
...
trans2es/utils/user_transfer.py
View file @
6a2b1cfe
...
@@ -73,6 +73,7 @@ class UserTransfer(object):
...
@@ -73,6 +73,7 @@ class UserTransfer(object):
try
:
try
:
res
[
"tag_list"
]
=
instance
.
get_user_tag_id_list
()
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_user_id_list"
]
=
cls
.
get_follow_user_id_list
(
userInstance
=
instance
)
# res["attention_group_id_list"] = instance.get_attention_group_id_list()
# 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