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
5b5e6032
Commit
5b5e6032
authored
May 30, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Plain Diff
add
parents
7c9943d3
5e5123c2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
488 additions
and
134 deletions
+488
-134
Project.xml
.idea/codeStyles/Project.xml
+25
-0
app_conf.xml
app_conf.xml
+1
-0
es.py
libs/es.py
+17
-16
group.py
search/utils/group.py
+71
-2
group.py
search/views/group.py
+21
-0
search_hotword.py
search/views/search_hotword.py
+69
-0
topic.py
search/views/topic.py
+0
-0
user.py
search/views/user.py
+125
-16
pictorial.json
trans2es/mapping/pictorial.json
+3
-1
user.json
trans2es/mapping/user.json
+4
-1
pictorial.py
trans2es/models/pictorial.py
+26
-6
tag.py
trans2es/models/tag.py
+37
-26
user.py
trans2es/models/user.py
+45
-23
type_info.py
trans2es/type_info.py
+14
-17
pictorial_transfer.py
trans2es/utils/pictorial_transfer.py
+9
-7
tag_transfer.py
trans2es/utils/tag_transfer.py
+16
-15
user_transfer.py
trans2es/utils/user_transfer.py
+5
-4
No files found.
.idea/codeStyles/Project.xml
View file @
5b5e6032
...
...
@@ -24,5 +24,29 @@
<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
app_conf.xml
View file @
5b5e6032
...
...
@@ -17,5 +17,6 @@
<element
value=
"search.views.contrast_similar"
/>
<element
value=
"injection.data_sync.tasks"
/>
<element
value=
"search.views.contrast_similar"
/>
<element
value=
"search.views.search_hotword"
/>
</config>
</gm_rpcd_config>
libs/es.py
View file @
5b5e6032
...
...
@@ -155,9 +155,9 @@ class ESPerform(object):
bulk_actions
=
[]
if
sub_index_name
==
"topic"
or
\
sub_index_name
==
"topic-star-routing"
or
\
sub_index_name
==
"topic-high-star"
:
if
sub_index_name
==
"topic"
or
\
sub_index_name
==
"topic-star-routing"
or
\
sub_index_name
==
"topic-high-star"
:
for
data
in
data_list
:
if
data
:
bulk_actions
.
append
({
...
...
@@ -232,7 +232,7 @@ class ESPerform(object):
return
{
"total_count"
:
0
,
"hits"
:
[]}
@classmethod
def
get_analyze_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
):
def
get_analyze_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
):
try
:
assert
(
es_cli
is
not
None
)
...
...
@@ -242,7 +242,7 @@ class ESPerform(object):
logging
.
error
(
"index:
%
s is not existing,get_search_results error!"
%
official_index_name
)
return
None
res
=
es_cli
.
indices
.
analyze
(
index
=
official_index_name
,
body
=
query_body
)
res
=
es_cli
.
indices
.
analyze
(
index
=
official_index_name
,
body
=
query_body
)
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
@@ -276,7 +276,7 @@ class ESPerform(object):
if
high_num
>
3
:
logging
.
info
(
"check es_nodes_load high,cpu load:
%
s,ori_cpu_info:
%
s"
%
(
str
(
es_nodes_list
),
str
(
es_nodes_info_list
)))
str
(
es_nodes_list
),
str
(
es_nodes_info_list
)))
return
True
else
:
return
False
...
...
@@ -298,8 +298,8 @@ class ESPerform(object):
functions_list
+=
[
{
"filter"
:
{
"constant_score"
:{
"filter"
:{
"constant_score"
:
{
"filter"
:
{
"term"
:
{
"content_level"
:
6
}}
}
},
...
...
@@ -307,8 +307,8 @@ class ESPerform(object):
},
{
"filter"
:
{
"constant_score"
:{
"filter"
:{
"constant_score"
:
{
"filter"
:
{
"term"
:
{
"content_level"
:
5
}}
}
},
...
...
@@ -316,8 +316,8 @@ class ESPerform(object):
},
{
"filter"
:
{
"constant_score"
:{
"filter"
:{
"constant_score"
:
{
"filter"
:
{
"term"
:
{
"content_level"
:
4
}}
}
},
...
...
@@ -411,7 +411,7 @@ class ESPerform(object):
}
},
"_source"
:
{
"include"
:
[
"id"
,
"user_id"
]
"include"
:
[
"id"
,
"user_id"
]
},
"sort"
:
[
{
"_score"
:
{
"order"
:
"desc"
}},
...
...
@@ -420,7 +420,7 @@ class ESPerform(object):
],
"collapse"
:
{
"field"
:
"user_id"
}
}
}
if
len
(
have_read_topic_id_list
)
>
0
:
...
...
@@ -429,7 +429,8 @@ class ESPerform(object):
"id"
:
have_read_topic_id_list
}
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic-high-star"
,
query_body
=
q
,
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic-high-star"
,
query_body
=
q
,
offset
=
0
,
size
=
size
,
routing
=
"6"
)
topic_id_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
...
...
@@ -441,7 +442,7 @@ class ESPerform(object):
logging
.
info
(
"topic_id_list:
%
s"
%
str
(
topic_id_dict
))
return
topic_id_list
,
topic_id_dict
return
topic_id_list
,
topic_id_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
search/utils/group.py
View file @
5b5e6032
...
...
@@ -109,8 +109,6 @@ class GroupUtils(object):
"script"
:
{
"lang"
:
"expression"
,
"source"
:
"_score+doc['offline_score']"
# "lang":"painless",
# "source":"_score+params._source.offline_score"
},
"order"
:
"desc"
}
...
...
@@ -214,3 +212,74 @@ class GroupUtils(object):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
get_search_pictorial_topic
(
cls
,
query
,
offset
,
size
):
try
:
q
=
dict
()
multi_fields
=
{
'name'
:
4
,
'description'
:
4
,
'tag_name'
:
4
}
query_fields
=
[
'^'
.
join
((
k
,
str
(
v
)))
for
(
k
,
v
)
in
multi_fields
.
items
()]
multi_match
=
{
'query'
:
query
,
'type'
:
'cross_fields'
,
'operator'
:
'and'
,
'fields'
:
query_fields
,
}
q
[
'query'
]
=
{
'bool'
:
{
"must"
:
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"term"
:
{
"is_default"
:
0
}},
{
"range"
:
{
"topic_id_list"
:
{
"gte"
:
0
}}},
{
"term"
:
{
"is_cover"
:
True
}}
],
"should"
:
[
{
'multi_match'
:
multi_match
}
],
"minimum_should_match"
:
1
}
}
q
[
"_source"
]
=
{
"includes"
:
[
"id"
,
"is_online"
,
"is_deleted"
,
"is_default"
,
"topic_id_list"
,
"is_cover"
,
"offline_score"
,
"is_default"
]
}
q
[
"sort"
]
=
[
{
"_script"
:
{
"type"
:
"number"
,
"script"
:
{
"lang"
:
"expression"
,
"source"
:
"_score+doc['offline_score']"
},
"order"
:
"desc"
}
},
{
"_score"
:
{
"order"
:
"desc"
}
}
]
q
=
{}
q
[
"query"
]
=
{
"term"
:
{
"is_online"
:
True
}
}
logging
.
info
(
"get qqqqqqqq:
%
s"
%
q
)
es_cli_obj
=
ESPerform
.
get_cli
()
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
offset
,
size
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
return
result_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
None
search/views/group.py
View file @
5b5e6032
...
...
@@ -261,3 +261,24 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"pict_pictorial_ids_list"
:
[]}
@bind
(
"physical/search/pictorial_topic_sort"
)
def
search_physical
(
query
=
""
,
offset
=
0
,
size
=
10
):
"""
搜索页面搜索画报
:param query:
:param offset:
:param size:
:return:
1. query识别:允许模糊匹配
2. 召回部分:去掉无封面、无帖子、下线的、默认画报
3. rank部分:(和之前一样,下面只是粘贴过来)
"""
try
:
result_dicts
=
GroupUtils
.
get_search_pictorial_topic
(
query
,
offset
,
size
)
logging
.
info
(
"result_dicts:
%
s"
%
result_dicts
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"search_topic_ids"
:
[]}
search/views/search_hotword.py
0 → 100644
View file @
5b5e6032
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
gm_rpcd.all
import
bind
import
logging
import
traceback
import
json
from
libs.cache
import
redis_client
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
from
trans2es.models.tag
import
RegisterShowTag
,
Tag
import
random
@bind
(
"physical/search/search_hotword"
)
def
search_hotword
(
device_id
=-
1
):
"""
:remark:搜索页的热门灵感
内容组成:搜索推荐热词register_show_tag
个性化标签physical:linucb:tag_recommend:device_id:
核心词,需要去重community_tag collection 1
①先从后台随机取最多6个搜索推荐热词,不够6个则有多少取多少
②然后随机取和推荐热词一样数量的linUCB标签,取不够数则取核心标签,linUCB+核心词去重后的数量要和搜索推荐热词的数量一样
③最后打乱顺序填入到热门灵感中,超过3行的标签弃掉,不够3行不用管
:param query:
:param offset:
:param size:
:return:
"""
try
:
all_tag_name_list
=
set
()
# 获取搜索推荐热词
results_registr_tag
=
RegisterShowTag
.
objects
.
filter
(
is_deleted
=
False
,
is_online
=
1
)
.
count
()
results_tag
=
Tag
.
objects
.
filter
(
is_online
=
True
,
collection
=
1
)
.
count
()
tag_id
=
random
.
sample
(
range
(
1
,
results_registr_tag
),
1
)
results_tag_chose
=
Tag
.
objects
.
filter
(
id__in
=
tag_id
)
.
values_list
(
"name"
,
flat
=
True
)
for
i
in
results_tag_chose
:
all_tag_name_list
.
add
(
i
)
# 获取个性化标签
linucb_recommend_redis_prefix
=
"physical:linucb:tag_recommend:device_id:"
tag_recommend_redis_key
=
linucb_recommend_redis_prefix
+
str
(
device_id
)
linucb_recommend_tag_data
=
redis_client
.
get
(
tag_recommend_redis_key
)
linucb_recommend_tag_list
=
json
.
loads
(
linucb_recommend_tag_data
)
if
linucb_recommend_tag_data
else
[]
for
item
in
linucb_recommend_tag_list
:
results_tag_recommend
=
Tag
.
objects
.
filter
(
id
=
item
,
is_online
=
True
)
.
values_list
(
"name"
,
flat
=
True
)
all_tag_name_list
.
add
(
results_tag_recommend
[
0
])
if
len
(
all_tag_name_list
)
==
12
:
return
{
"recommend_tag_name"
:
list
(
all_tag_name_list
)}
logging
.
info
(
"get all_tag_name_list02:
%
s"
%
all_tag_name_list
)
# 取不够数则取核心标签
if
len
(
all_tag_name_list
)
<
12
:
for
i
in
range
(
0
,
12
):
tag_id
=
random
.
sample
(
range
(
1
,
results_tag
),
12
-
len
(
all_tag_name_list
))
results_tag_hexin
=
Tag
.
objects
.
filter
(
id__in
=
tag_id
)
.
values_list
(
"name"
,
flat
=
True
)
if
results_tag_hexin
not
in
all_tag_name_list
:
all_tag_name_list
.
add
(
results_tag_hexin
[
0
])
if
len
(
all_tag_name_list
)
>=
12
:
return
{
"recommend_tag_name"
:
list
(
all_tag_name_list
)}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"recommend_tag_name"
:
[]}
search/views/topic.py
View file @
5b5e6032
This diff is collapsed.
Click to expand it.
search/views/user.py
View file @
5b5e6032
...
...
@@ -14,7 +14,7 @@ from libs.es import ESPerform
@bind
(
"physical/search/recommend_user"
)
def
recommend_user
(
self_user_id
,
interesting_user_id
,
offset
=
0
,
size
=
10
):
def
recommend_user
(
self_user_id
,
interesting_user_id
,
offset
=
0
,
size
=
10
):
"""
:remark 点关注推荐用户
:param self_user_id:
...
...
@@ -29,25 +29,29 @@ def recommend_user(self_user_id,interesting_user_id,offset=0,size=10):
if
not
isinstance
(
interesting_user_id
,
int
):
interesting_user_id
=
-
1
#获取es链接对象
#
获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
#获取关注用户列表
(
self_attention_user_id_list
,
recursion_attention_user_id_list
)
=
UserUtils
.
get_attention_user_list
([
self_user_id
,
interesting_user_id
],
self_user_id
,
es_cli_obj
)
# 获取关注用户列表
(
self_attention_user_id_list
,
recursion_attention_user_id_list
)
=
UserUtils
.
get_attention_user_list
(
[
self_user_id
,
interesting_user_id
],
self_user_id
,
es_cli_obj
)
#去除自身及感兴趣的用户ID
#
去除自身及感兴趣的用户ID
self_attention_user_id_list
.
append
(
self_user_id
)
self_attention_user_id_list
.
append
(
interesting_user_id
)
recommend_user_list
=
UserUtils
.
get_recommend_user_list
(
self_attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
,
es_cli_obj
)
recommend_user_list
=
UserUtils
.
get_recommend_user_list
(
self_attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
,
es_cli_obj
)
return
recommend_user_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@bind
(
"physical/search/batch_recommend_user"
)
def
batch_recommend_user
(
self_user_id
,
interesting_user_id_list
,
offset
=
0
,
size
=
10
):
def
batch_recommend_user
(
self_user_id
,
interesting_user_id_list
,
offset
=
0
,
size
=
10
):
"""
:remark 点关注推荐用户 - 批量接口
:param self_user_id:
...
...
@@ -57,23 +61,129 @@ def batch_recommend_user(self_user_id,interesting_user_id_list,offset=0,size=10)
:return:
"""
try
:
if
not
isinstance
(
self_user_id
,
int
):
if
not
isinstance
(
self_user_id
,
int
):
self_user_id
=
-
1
#获取es链接对象
#
获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
#获取关注用户列表
(
need_filter_attention_user_id_list
,
attention_user_dict_list
,
attention_user_id_list
)
=
UserUtils
.
get_batch_attention_user_list
(
interesting_user_id_list
,
self_user_id
,
es_cli_obj
)
# 获取关注用户列表
(
need_filter_attention_user_id_list
,
attention_user_dict_list
,
attention_user_id_list
)
=
UserUtils
.
get_batch_attention_user_list
(
interesting_user_id_list
,
self_user_id
,
es_cli_obj
)
#去除自身及感兴趣的用户ID
# 去除自身及感兴趣的用户ID
need_filter_attention_user_id_list
.
append
(
self_user_id
)
recommend_user_dict
=
UserUtils
.
get_batch_recommend_user_dict
(
need_filter_attention_user_id_list
=
need_filter_attention_user_id_list
,
attention_user_id_list
=
attention_user_id_list
,
attention_user_dict_list
=
attention_user_dict_list
,
self_user_id
=
self_user_id
,
offset
=
offset
,
size
=
size
,
es_cli_obj
=
es_cli_obj
)
recommend_user_dict
=
UserUtils
.
get_batch_recommend_user_dict
(
need_filter_attention_user_id_list
=
need_filter_attention_user_id_list
,
attention_user_id_list
=
attention_user_id_list
,
attention_user_dict_list
=
attention_user_dict_list
,
self_user_id
=
self_user_id
,
offset
=
offset
,
size
=
size
,
es_cli_obj
=
es_cli_obj
)
logging
.
info
(
"duan add,recommend_user_dict:
%
s"
%
str
(
recommend_user_dict
))
return
recommend_user_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{}
\ No newline at end of file
return
{}
@bind
(
"physical/search/search_user"
)
def
search_user
(
query
=
""
,
offset
=
0
,
size
=
10
):
"""
:remark 搜索用户
:param query:
:param offset:
:param size:
:return:
搜索域:用户名称
1.识别query:允许模糊匹配
2.召回部分:全部 线上状态用户
3.rank部分:一级-是否推荐,二级-发帖数
"""
try
:
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
{}
# 先获取完全匹配的用户ID
sheer_user_id
=
[]
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"nick_name_pre"
:
query
}
},
{
"term"
:
{
"is_recommend"
:
True
}
}
]
}
}
q
[
"sort"
]
=
{
"count_topic"
:
{
"order"
:
"desc"
}
}
# que = {"query": {"term": {"nick_name_pre": query}}}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
0
,
10
)
res
=
result_dict
[
"hits"
]
if
len
(
res
)
>
0
:
user_id
=
[
item
[
"_source"
][
"user_id"
]
for
item
in
res
]
sheer_user_id
.
append
(
user_id
)
logging
.
info
(
"get res:
%
s"
%
res
)
# 获取模糊匹配的用户ID
multi_match
=
{
"fields"
:
[
"nick_name"
],
"type"
:
"cross_fields"
,
"operator"
:
"and"
,
"query"
:
query
}
q
=
{}
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[{
"multi_match"
:
multi_match
},
{
"term"
:
{
"is_online"
:
True
}
}
]
}
}
q
[
"sort"
]
=
{
"is_recommend"
:
{
"order"
:
"desc"
},
"count_topic"
:
{
"order"
:
"desc"
},
}
logging
.
info
(
"get q:
%
s"
%
q
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
,
size
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
search_user_id
=
[]
res
=
result_dict
[
"hits"
]
if
len
(
res
)
>
0
:
search_user_id
=
[
item
[
"_source"
][
"user_id"
]
for
item
in
res
]
return
{
"sheer_user_id"
:
sheer_user_id
,
"search_user_id"
:
search_user_id
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"sheer_user_id"
:
[],
"search_user_id"
:
[]}
trans2es/mapping/pictorial.json
View file @
5b5e6032
...
...
@@ -18,6 +18,7 @@
"topic_id_list"
:{
"type"
:
"long"
},
"effective"
:{
"type"
:
"boolean"
},
"offline_score"
:{
"type"
:
"long"
},
"is_default"
:{
"type"
:
"long"
}
"is_default"
:{
"type"
:
"long"
},
"is_cover"
:{
"type"
:
"boolean"
}
}
}
\ No newline at end of file
trans2es/mapping/user.json
View file @
5b5e6032
...
...
@@ -4,6 +4,7 @@
"id"
:{
"type"
:
"long"
},
"user_id"
:{
"type"
:
"long"
},
"nick_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
//昵称
"nick_name_pre"
:{
"type"
:
"text"
,
"analyzer"
:
"not_analyzed"
},
//昵称
"profile_pic"
:{
"type"
:
"text"
},
//头像
"gender"
:{
"type"
:
"integer"
},
"is_online"
:{
"type"
:
"boolean"
},
//是否上线
...
...
@@ -60,6 +61,7 @@
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"create_time_val"
:{
"type"
:
"long"
},
"update_time_val"
:{
"type"
:
"long"
}
"update_time_val"
:{
"type"
:
"long"
},
"count_topic"
:{
"type"
:
"long"
}
}
}
\ No newline at end of file
trans2es/models/pictorial.py
View file @
5b5e6032
...
...
@@ -63,27 +63,27 @@ class Pictorial(models.Model):
def
get_topic_id
(
self
):
try
:
topic_id_list
=
list
(
PictorialTopics
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"topic_id"
,
flat
=
True
))
topic_id_list
=
list
(
PictorialTopics
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"topic_id"
,
flat
=
True
))
return
topic_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_effective
(
self
,
topic_id_list
):
def
get_effective
(
self
,
topic_id_list
):
try
:
effective_num
=
0
ret
=
False
for
topic_id
in
topic_id_list
:
topic_id_object
=
Topic
.
objects
.
filter
(
id
=
int
(
topic_id
))
.
first
()
if
topic_id_object
and
topic_id_object
.
is_online
and
int
(
topic_id_object
.
content_level
)
in
[
0
,
3
,
4
,
5
]:
if
topic_id_object
and
topic_id_object
.
is_online
and
int
(
topic_id_object
.
content_level
)
in
[
0
,
3
,
4
,
5
]:
effective_num
+=
1
if
effective_num
>=
5
:
ret
=
True
break
return
ret
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
@@ -109,7 +109,8 @@ class Pictorial(models.Model):
def
get_tag_by_id
(
self
):
try
:
tag_id_list
=
list
(
PictorialTag
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
))
tag_id_list
=
list
(
PictorialTag
.
objects
.
filter
(
pictorial_id
=
self
.
id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
))
return
tag_id_list
except
:
...
...
@@ -125,6 +126,25 @@ class Pictorial(models.Model):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_is_cover
(
self
,
topic_id_list
):
try
:
effective_num
=
0
ret
=
False
for
topic_id
in
topic_id_list
:
topic_id_object
=
Topic
.
objects
.
filter
(
id
=
int
(
topic_id
))
.
first
()
if
topic_id_object
and
topic_id_object
.
is_online
and
int
(
topic_id_object
.
content_level
)
in
[
3
,
4
,
5
,
6
]:
effective_num
+=
1
if
effective_num
>=
5
:
ret
=
True
break
return
ret
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
class
PictorialTag
(
models
.
Model
):
"""画报关注标签"""
...
...
trans2es/models/tag.py
View file @
5b5e6032
...
...
@@ -12,10 +12,10 @@ import datetime
class
TopicTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"帖子标签"
db_table
=
"community_topictag"
verbose_name
=
u"帖子标签"
db_table
=
"community_topictag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"标签ID"
)
topic_id
=
models
.
IntegerField
(
verbose_name
=
u"帖子ID"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否在线"
)
...
...
@@ -25,73 +25,84 @@ class TopicTag(models.Model):
class
AccountUserTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"用户标签"
db_table
=
"account_user_tag"
verbose_name
=
u"用户标签"
db_table
=
"account_user_tag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"标签ID"
)
user
=
models
.
IntegerField
(
verbose_name
=
u"用户ID"
)
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
))
is_body_esthetics
=
models
.
IntegerField
(
verbose_name
=
u"是否有用标签"
)
class
Tag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"标签"
db_table
=
"community_tag"
verbose_name
=
u"标签"
db_table
=
"community_tag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
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
)
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
)
icon_url
=
models
.
CharField
(
verbose_name
=
u"icon_url"
,
max_length
=
120
)
collection
=
models
.
IntegerField
(
verbose_name
=
u"是否编辑"
)
is_ai
=
models
.
IntegerField
(
verbose_name
=
u"是否ai"
)
is_own
=
models
.
IntegerField
(
verbose_name
=
u"是否ins上自带"
)
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
))
class
CommunityTagFollow
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"用户关注标签"
db_table
=
"community_tag_follow"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
verbose_name
=
u"用户关注标签"
db_table
=
"community_tag_follow"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否上线"
)
user_id
=
models
.
IntegerField
(
verbose_name
=
u"用户ID"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"帖子ID"
)
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
))
class
CommunityTagTypeRelation
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"标签类型对应关系"
db_table
=
"community_tag_type_relation"
verbose_name
=
u"标签类型对应关系"
db_table
=
"community_tag_type_relation"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否上线"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u"标签ID"
)
tag_type_id
=
models
.
IntegerField
(
verbose_name
=
u"标签类型ID"
)
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
))
class
CommunityTagType
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"标签类型"
db_table
=
"community_tag_type"
verbose_name
=
u"标签类型"
db_table
=
"community_tag_type"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
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
=
64
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
name
=
models
.
CharField
(
verbose_name
=
u"名称"
,
max_length
=
64
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
class
RegisterShowTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
"搜索热词"
db_table
=
"register_show_tag"
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
is_deleted
=
models
.
IntegerField
(
verbose_name
=
u"是否删除"
)
is_online
=
models
.
IntegerField
(
verbose_name
=
u"是否在线"
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
"标签ID"
)
trans2es/models/user.py
View file @
5b5e6032
...
...
@@ -16,6 +16,8 @@ from .tag import AccountUserTag
from
.topic
import
Topic
from
.user_extra
import
UserExtra
from
.pictorial
import
PictorialFollow
from
.topic
import
Topic
class
User
(
models
.
Model
):
class
Meta
:
...
...
@@ -35,9 +37,10 @@ class User(models.Model):
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
@classmethod
def
get_user_nick_name
(
cls
,
user_id
):
def
get_user_nick_name
(
cls
,
user_id
):
try
:
nick_name
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
user_id
)
.
values_list
(
"nick_name"
)
.
first
()
nick_name
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
user_id
)
.
values_list
(
"nick_name"
)
.
first
()
return
nick_name
[
0
]
except
:
...
...
@@ -47,7 +50,8 @@ class User(models.Model):
def
get_is_recommend_flag
(
self
):
is_shadow
=
False
is_recommend
=
False
query_sql
=
UserExtra
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
,
is_deleted
=
False
,
is_online
=
True
)
query_sql
=
UserExtra
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
,
is_deleted
=
False
,
is_online
=
True
)
for
record
in
query_sql
:
is_recommend
=
record
.
is_recommend
is_shadow
=
record
.
is_shadow
...
...
@@ -58,8 +62,9 @@ class User(models.Model):
latest_topic_time_val
=
-
1
# 获取该用户最新发帖时间
topic_records
=
Topic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
order_by
(
"-update_time"
)
.
values_list
(
"update_time"
,
flat
=
True
)
.
first
()
topic_records
=
Topic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
order_by
(
"-update_time"
)
.
values_list
(
"update_time"
,
flat
=
True
)
.
first
()
if
topic_records
:
tzlc_topic_update_time
=
tzlc
(
topic_records
)
latest_topic_time_val
=
int
(
time
.
mktime
(
tzlc_topic_update_time
.
timetuple
()))
...
...
@@ -75,7 +80,8 @@ class User(models.Model):
logging
.
info
(
"get follow_user_id_list :
%
s"
%
follow_user_id_list
)
for
i
in
range
(
0
,
len
(
follow_user_id_list
),
1000
):
logging
.
info
(
"get follow_user_id_list :
%
s"
%
follow_user_id_list
[
i
:
i
+
1000
])
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
])
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
])
for
detail_data
in
sql_data_list
:
item
=
{
"user_id"
:
detail_data
.
user_id
,
...
...
@@ -88,7 +94,8 @@ class User(models.Model):
def
get_attention_group_id_list
(
self
):
try
:
attention_group_id_list
=
list
()
query_results
=
GroupUserRole
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
True
,
user_id
=
self
.
user_id
)
query_results
=
GroupUserRole
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
True
,
user_id
=
self
.
user_id
)
for
item
in
query_results
:
item_dict
=
{
"group_id"
:
item
.
group_id
,
...
...
@@ -104,15 +111,16 @@ class User(models.Model):
def
get_attention_pictorial_id_list
(
self
):
try
:
attention_pictorial_id_list
=
list
()
query_results
=
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
True
,
user_id
=
self
.
user_id
)
logging
.
info
(
"get PictorialFollow:
%
s"
%
query_results
)
query_results
=
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
True
,
user_id
=
self
.
user_id
)
logging
.
info
(
"get PictorialFollow:
%
s"
%
query_results
)
for
item
in
query_results
:
item_dict
=
{
"pictorial_id"
:
item
.
pictorial_id
,
"update_time_val"
:
time
.
mktime
(
tzlc
(
item
.
update_time
)
.
timetuple
())
}
attention_pictorial_id_list
.
append
(
item_dict
)
logging
.
info
(
"get user_id:
%
s"
%
self
.
user_id
)
logging
.
info
(
"get user_id:
%
s"
%
self
.
user_id
)
logging
.
info
(
"get same_pictorial_user_id_list:
%
s"
%
attention_pictorial_id_list
)
...
...
@@ -149,25 +157,29 @@ class User(models.Model):
def
get_same_pictorial_user_id_list
(
self
):
#todo 有的同组数据过大,导致celery cpu过高,暂时限制同组的数据大小,后续可能会去掉同组的数据
#
todo 有的同组数据过大,导致celery cpu过高,暂时限制同组的数据大小,后续可能会去掉同组的数据
same_pictorial_user_id_list
=
list
()
pictorial_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
values_list
(
"pictorial_id"
,
flat
=
True
))
pictorial_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id
=
self
.
user_id
)
.
values_list
(
"pictorial_id"
,
flat
=
True
))
for
pictorial_id
in
pictorial_items_list
:
user_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
pictorial_id
=
pictorial_id
)
.
values_list
(
"user_id"
,
flat
=
True
))
user_items_list
=
list
(
PictorialFollow
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
pictorial_id
=
pictorial_id
)
.
values_list
(
"user_id"
,
flat
=
True
))
for
user_id
in
user_items_list
:
same_pictorial_user_id_list
.
append
(
user_id
)
if
len
(
same_pictorial_user_id_list
)
>=
100
:
if
len
(
same_pictorial_user_id_list
)
>=
100
:
break
if
len
(
same_pictorial_user_id_list
)
>=
100
:
if
len
(
same_pictorial_user_id_list
)
>=
100
:
break
logging
.
info
(
"get same user_id:
%
s"
%
self
.
user_id
)
logging
.
info
(
"get same_pictorial_user_id_list:
%
s"
%
same_pictorial_user_id_list
)
logging
.
info
(
"get same user_id:
%
s"
%
self
.
user_id
)
logging
.
info
(
"get same_pictorial_user_id_list:
%
s"
%
same_pictorial_user_id_list
)
same_pictorial_detail_list
=
list
()
for
i
in
range
(
0
,
len
(
same_pictorial_user_id_list
),
200
):
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
same_pictorial_user_id_list
[
i
:
i
+
1000
])
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
same_pictorial_user_id_list
[
i
:
i
+
1000
])
for
detail_data
in
sql_data_list
:
item
=
{
"user_id"
:
detail_data
.
user_id
,
...
...
@@ -181,7 +193,8 @@ class User(models.Model):
try
:
user_tag_id_list
=
list
()
query_results
=
AccountUserTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user
=
self
.
user_id
,
is_deleted
=
False
)
query_results
=
AccountUserTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user
=
self
.
user_id
,
is_deleted
=
False
)
for
item
in
query_results
:
user_tag_id_list
.
append
(
item
.
tag_id
)
...
...
@@ -194,11 +207,21 @@ class User(models.Model):
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
)
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
return
[]
def
get_topic_number
(
self
):
try
:
number
=
Topic
.
objects
.
filter
(
user_id
=
self
.
user_id
)
.
count
()
return
number
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
0
trans2es/type_info.py
View file @
5b5e6032
...
...
@@ -14,7 +14,7 @@ import sys
from
libs.cache
import
redis_client
import
copy
from
trans2es.models
import
topic
,
user
,
pick_celebrity
,
group
,
celebrity
,
tag
,
contrast_similar
,
pictorial
from
trans2es.models
import
topic
,
user
,
pick_celebrity
,
group
,
celebrity
,
tag
,
contrast_similar
,
pictorial
from
trans2es.utils.user_transfer
import
UserTransfer
from
trans2es.utils.pick_celebrity_transfer
import
PickCelebrityTransfer
from
trans2es.utils.group_transfer
import
GroupTransfer
...
...
@@ -196,7 +196,7 @@ class TypeInfo(object):
old_data
[
"is_history"
]
=
True
data_list
.
append
(
old_data
)
if
int_ori_topic_star
>=
4
:
if
int_ori_topic_star
>=
4
:
topic_data_high_star_list
.
append
(
old_data
)
redis_client
.
hset
(
self
.
physical_topic_star
,
data
[
"id"
],
data
[
"content_level"
])
# data_list = [
...
...
@@ -207,12 +207,11 @@ class TypeInfo(object):
# ]
# ESPerform.es_helpers_bulk(ESPerform.get_cli(), data_list, "topic-star")
if
data
[
"content_level"
]
and
int
(
data
[
"content_level"
])
>=
4
:
if
data
[
"content_level"
]
and
int
(
data
[
"content_level"
])
>=
4
:
topic_data_high_star_list
.
append
(
data
)
data_list
.
append
(
data
)
return
(
data_list
,
topic_data_high_star_list
)
return
(
data_list
,
topic_data_high_star_list
)
def
elasticsearch_bulk_insert_data
(
self
,
sub_index_name
,
data_list
,
es
=
None
):
...
...
@@ -255,17 +254,17 @@ class TypeInfo(object):
else
:
qs
=
self
.
model
.
objects
.
all
()
end
=
time
.
time
()
time0
=
end
-
begin
time0
=
end
-
begin
begin
=
time
.
time
()
instance_list
=
qs
.
filter
(
pk__in
=
pk_list
)
end
=
time
.
time
()
time1
=
end
-
begin
time1
=
end
-
begin
begin
=
time
.
time
()
data_list
,
topic_data_high_star_list
=
self
.
bulk_get_data
(
instance_list
)
end
=
time
.
time
()
time2
=
end
-
begin
time2
=
end
-
begin
begin
=
time
.
time
()
# logging.info("get sub_index_name:%s"%sub_index_name)
...
...
@@ -277,7 +276,7 @@ class TypeInfo(object):
es
=
es
,
)
if
sub_index_name
==
"topic"
:
if
sub_index_name
==
"topic"
:
self
.
elasticsearch_bulk_insert_data
(
sub_index_name
=
"topic-star-routing"
,
data_list
=
data_list
,
...
...
@@ -285,7 +284,7 @@ class TypeInfo(object):
)
# 同时写4星及以上的帖子
if
len
(
topic_data_high_star_list
)
>
0
:
if
len
(
topic_data_high_star_list
)
>
0
:
self
.
elasticsearch_bulk_insert_data
(
sub_index_name
=
"topic-high-star"
,
data_list
=
topic_data_high_star_list
,
...
...
@@ -293,9 +292,8 @@ class TypeInfo(object):
)
end
=
time
.
time
()
time3
=
end
-
begin
logging
.
info
(
"duan add,insert_table_by_pk_list time cost:
%
ds,
%
ds,
%
ds,
%
ds"
%
(
time0
,
time1
,
time2
,
time3
))
time3
=
end
-
begin
logging
.
info
(
"duan add,insert_table_by_pk_list time cost:
%
ds,
%
ds,
%
ds,
%
ds"
%
(
time0
,
time1
,
time2
,
time3
))
def
insert_table_chunk
(
self
,
sub_index_name
,
table_chunk
,
es
=
None
):
try
:
...
...
@@ -317,7 +315,7 @@ class TypeInfo(object):
auto_create_index
=
True
)
logging
.
info
(
"es_helpers_bulk,sub_index_name:
%
s,data_list len:
%
d"
%
(
sub_index_name
,
len
(
data_list
)))
logging
.
info
(
"es_helpers_bulk,sub_index_name:
%
s,data_list len:
%
d"
%
(
sub_index_name
,
len
(
data_list
)))
stage_3_time
=
time
.
time
()
end_clock
=
time
.
clock
()
...
...
@@ -355,8 +353,8 @@ def get_type_info_map():
name
=
'topic-star'
,
type
=
'topic-star'
,
model
=
topic
.
Topic
,
query_deferred
=
lambda
:
topic
.
Topic
.
objects
.
all
()
.
query
,
#
假的
get_data_func
=
TopicTransfer
.
get_topic_data
,
#
假的
query_deferred
=
lambda
:
topic
.
Topic
.
objects
.
all
()
.
query
,
#
假的
get_data_func
=
TopicTransfer
.
get_topic_data
,
#
假的
bulk_insert_chunk_size
=
100
,
round_insert_chunk_size
=
5
,
round_insert_period
=
2
,
...
...
@@ -525,4 +523,3 @@ def get_type_info_map():
_get_type_info_map_result
=
type_info_map
return
type_info_map
trans2es/utils/pictorial_transfer.py
View file @
5b5e6032
...
...
@@ -7,26 +7,27 @@ import traceback
from
libs.tools
import
tzlc
from
trans2es.models.topic
import
Topic
class
PictorialTransfer
(
object
):
def
__init__
(
self
):
pass
@classmethod
def
get_offline_score
(
cls
,
instance
,
topic_id_list
):
def
get_offline_score
(
cls
,
instance
,
topic_id_list
):
try
:
total_offline_score
=
0
topic_image_num
=
0
for
topic_id
in
topic_id_list
:
topic_image_num
+=
Topic
.
get_topic_image_num
(
topic_id
)
if
topic_image_num
>=
6
and
topic_image_num
<=
10
:
if
topic_image_num
>=
6
and
topic_image_num
<=
10
:
total_offline_score
+=
30
elif
topic_image_num
>
10
and
topic_image_num
<=
20
:
elif
topic_image_num
>
10
and
topic_image_num
<=
20
:
total_offline_score
+=
60
elif
topic_image_num
>
20
and
topic_image_num
<=
50
:
elif
topic_image_num
>
20
and
topic_image_num
<=
50
:
total_offline_score
+=
80
elif
topic_image_num
>
50
:
elif
topic_image_num
>
50
:
total_offline_score
+=
100
total_offline_score
+=
instance
.
add_score
...
...
@@ -62,10 +63,11 @@ class PictorialTransfer(object):
tag_id_list
=
instance
.
get_tag_by_id
()
res
[
"tag_id"
]
=
tag_id_list
res
[
"tag_name"
]
=
instance
.
get_tag_by_name
(
tag_id_list
)
res
[
"topic_id_list"
]
=
instance
.
get_topic_id
()
res
[
"topic_id_list"
]
=
instance
.
get_topic_id
()
res
[
"effective"
]
=
instance
.
get_effective
(
res
[
"topic_id_list"
])
res
[
"offline_score"
]
=
cls
.
get_offline_score
(
instance
,
res
[
"topic_id_list"
])
res
[
"offline_score"
]
=
cls
.
get_offline_score
(
instance
,
res
[
"topic_id_list"
])
res
[
"is_default"
]
=
instance
.
is_default
res
[
"is_cover"
]
=
instance
.
get_is_cover
(
res
[
"topic_id_list"
])
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
trans2es/utils/tag_transfer.py
View file @
5b5e6032
...
...
@@ -8,16 +8,15 @@ import logging
import
traceback
from
libs.tools
import
tzlc
from
trans2es.models.topic
import
Topic
from
trans2es.models.tag
import
TopicTag
,
CommunityTagType
,
CommunityTagTypeRelation
from
trans2es.models.tag
import
TopicTag
,
CommunityTagType
,
CommunityTagTypeRelation
import
datetime
from
django.conf
import
settings
class
TagTransfer
(
object
):
@classmethod
def
get_tag_name_data
(
cls
,
instance
):
def
get_tag_name_data
(
cls
,
instance
):
try
:
res
=
dict
()
res
[
"name"
]
=
instance
.
name
...
...
@@ -28,7 +27,7 @@ class TagTransfer(object):
return
dict
()
@classmethod
def
get_tag_data
(
cls
,
instance
):
def
get_tag_data
(
cls
,
instance
):
try
:
res
=
dict
()
...
...
@@ -36,14 +35,14 @@ class TagTransfer(object):
tag_name_terms_list
=
list
()
for
i
in
range
(
len
(
instance
.
name
)):
for
j
in
range
(
i
,
len
(
instance
.
name
)
+
1
):
for
j
in
range
(
i
,
len
(
instance
.
name
)
+
1
):
name_term
=
instance
.
name
[
i
:
j
]
.
strip
()
if
name_term
:
tag_name_terms_list
.
append
(
name_term
.
lower
())
res
[
"suggest"
]
=
{
"input"
:
tag_name_terms_list
,
"contexts"
:{
"input"
:
tag_name_terms_list
,
"contexts"
:
{
"is_online"
:
[
instance
.
is_online
],
"is_deleted"
:
[
instance
.
is_deleted
]
}
...
...
@@ -54,24 +53,27 @@ class TagTransfer(object):
topic_num
=
0
res
[
"near_new_topic_num"
]
=
topic_num
if
instance
.
is_online
==
True
and
instance
.
is_deleted
==
False
:
if
instance
.
is_online
==
True
and
instance
.
is_deleted
==
False
:
topic_id_list
=
list
()
sql_result_results
=
list
(
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
tag_id
=
instance
.
id
)
.
values_list
(
"topic_id"
,
"is_online"
))
for
topic_id
,
is_online
in
sql_result_results
:
for
topic_id
,
is_online
in
sql_result_results
:
if
is_online
:
topic_id_list
.
append
(
topic_id
)
time_base_val
=
datetime
.
datetime
.
strftime
(
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
-
7
),
"
%
Y-
%
m-
%
d"
)
time_base_val
=
datetime
.
datetime
.
strftime
(
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
-
7
),
"
%
Y-
%
m-
%
d"
)
for
topic_begin_index
in
range
(
0
,
len
(
topic_id_list
),
100
):
cur_topic_num
=
Topic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
topic_id_list
[
topic_begin_index
:
topic_begin_index
+
100
],
create_time__gte
=
time_base_val
)
.
count
()
for
topic_begin_index
in
range
(
0
,
len
(
topic_id_list
),
100
):
cur_topic_num
=
Topic
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
topic_id_list
[
topic_begin_index
:
topic_begin_index
+
100
],
create_time__gte
=
time_base_val
)
.
count
()
topic_num
+=
cur_topic_num
res
[
"near_new_topic_num"
]
=
topic_num
tag_type_sql_list
=
CommunityTagTypeRelation
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
tag_id
=
instance
.
id
)
.
values_list
(
"tag_type_id"
,
flat
=
True
)
tag_type_sql_list
=
CommunityTagTypeRelation
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
tag_id
=
instance
.
id
)
.
values_list
(
"tag_type_id"
,
flat
=
True
)
tag_type_list
=
list
()
for
tag_type_id
in
tag_type_sql_list
:
tag_type_list
.
append
(
tag_type_id
)
...
...
@@ -83,4 +85,4 @@ class TagTransfer(object):
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
dict
()
\ No newline at end of file
return
dict
()
trans2es/utils/user_transfer.py
View file @
5b5e6032
...
...
@@ -21,8 +21,9 @@ class UserTransfer(object):
follow_user_detail_list
=
list
()
for
i
in
range
(
0
,
len
(
follow_user_id_list
),
1000
):
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
],
is_online
=
True
,
is_deleted
=
False
)
sql_data_list
=
User
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
user_id__in
=
follow_user_id_list
[
i
:
i
+
1000
],
is_online
=
True
,
is_deleted
=
False
)
for
detail_data
in
sql_data_list
:
item
=
{
"user_id"
:
detail_data
.
user_id
,
...
...
@@ -40,13 +41,14 @@ class UserTransfer(object):
res
[
"id"
]
=
instance
.
id
res
[
"user_id"
]
=
instance
.
user_id
res
[
"nick_name"
]
=
instance
.
nick_name
res
[
"nick_name_pre"
]
=
instance
.
nick_name
res
[
"profile_pic"
]
=
instance
.
profile_pic
res
[
"gender"
]
=
instance
.
gender
res
[
"city_id"
]
=
instance
.
city_id
res
[
"country_id"
]
=
instance
.
country_id
res
[
"is_online"
]
=
instance
.
is_online
res
[
"is_deleted"
]
=
instance
.
is_deleted
res
[
"count_topic"
]
=
instance
.
get_topic_number
()
try
:
(
is_recommend
,
is_shadow
)
=
instance
.
get_is_recommend_flag
()
res
[
"is_recommend"
]
=
is_recommend
...
...
@@ -95,7 +97,6 @@ class UserTransfer(object):
res
[
"attention_pictorial_id_list"
]
=
[]
res
[
"same_pictorial_user_id_list"
]
=
[]
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
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