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
8a589d3c
Commit
8a589d3c
authored
Jun 24, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
efc03161
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
43 deletions
+102
-43
misc.xml
.idea/misc.xml
+1
-1
physical.iml
.idea/physical.iml
+1
-1
topic.py
search/utils/topic.py
+57
-11
group.py
search/views/group.py
+25
-19
topic.json
trans2es/mapping/topic.json
+9
-8
topic.py
trans2es/models/topic.py
+9
-3
No files found.
.idea/misc.xml
View file @
8a589d3c
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.6 (
physical1
)"
project-jdk-type=
"Python SDK"
/>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.6 (
LiXiaoFang
)"
project-jdk-type=
"Python SDK"
/>
<component
name=
"PyCharmProfessionalAdvertiser"
>
<option
name=
"shown"
value=
"true"
/>
</component>
...
...
.idea/physical.iml
View file @
8a589d3c
...
...
@@ -2,7 +2,7 @@
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.6 (
physical1
)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.6 (
LiXiaoFang
)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
<component
name=
"TestRunnerService"
>
...
...
search/utils/topic.py
View file @
8a589d3c
...
...
@@ -14,7 +14,6 @@ from trans2es.models.pictorial import PictorialTopics
from
libs.cache
import
redis_client
class
TopicUtils
(
object
):
@classmethod
...
...
@@ -35,7 +34,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
)
...
...
@@ -126,7 +125,8 @@ class TopicUtils(object):
def
get_recommend_topic_ids
(
cls
,
user_id
,
tag_id
,
offset
,
size
,
single_size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
filter_topic_id_list
=
[],
test_score
=
False
,
must_topic_id_list
=
[],
recommend_tag_list
=
[],
user_similar_score_list
=
[],
index_type
=
"topic-test"
,
routing
=
None
,
attention_tag_list
=
[],
user_similar_score_list
=
[],
index_type
=
"topic-test"
,
routing
=
None
,
attention_tag_list
=
[],
linucb_user_id_list
=
[],
disable_collpase
=
False
):
"""
:remark:获取首页推荐帖子列表
...
...
@@ -174,18 +174,18 @@ class TopicUtils(object):
}
]
if
user_id
and
user_id
>
0
:
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
:
if
len
(
user_similar_list
)
>
0
:
functions_list
.
extend
(
user_similar_list
)
if
len
(
attention_user_id_list
)
>
0
:
functions_list
.
append
(
{
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"terms"
:
{
"user_id"
:
attention_user_id_list
}}}},
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"terms"
:
{
"user_id"
:
attention_user_id_list
}}}},
"weight"
:
100
,
}
)
...
...
@@ -272,7 +272,7 @@ class TopicUtils(object):
]
query_function_score
[
"query"
][
"bool"
][
"minimum_should_match"
]
=
1
query_function_score
[
"query"
][
"bool"
][
"filter"
]
.
append
(
{
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
6
}}}
{
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
6
}}}
)
else
:
if
"must_not"
in
query_function_score
[
"query"
][
"bool"
]:
...
...
@@ -337,7 +337,7 @@ class TopicUtils(object):
@classmethod
def
userful_tag_topic_list
(
cls
,
user_id
,
have_read_topic_list
,
size
,
index_type
=
"topic-high-star"
,
routing
=
None
,
useful_tag_list
=
[]):
index_type
=
"topic-high-star"
,
routing
=
None
,
useful_tag_list
=
[]):
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
...
...
@@ -376,7 +376,7 @@ class TopicUtils(object):
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"terms"
:
{
"useful_tag_list"
:
useful_tag_list
}},
{
"term"
:{
"content_level"
:
6
}}
{
"term"
:
{
"content_level"
:
6
}}
],
"must_not"
:
{
"terms"
:
{
...
...
@@ -406,7 +406,8 @@ class TopicUtils(object):
"includes"
:
[
"id"
]
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
size
=
size
,
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
()
...
...
@@ -928,7 +929,35 @@ class TopicUtils(object):
"order"
:
"desc"
},
})
elif
sort_by
==
TOPIC_SEARCH_SORT
.
REAL_VOTE_AEC
:
sort_rule
.
append
({
"related_billboard.real_vote_cnt"
:
{
"order"
:
"asc"
,
"nested_path"
:
"related_billboard"
},
})
elif
sort_by
==
TOPIC_SEARCH_SORT
.
REAL_VOTE_DESC
:
sort_rule
.
append
({
"related_billboard.real_vote_cnt"
:
{
"order"
:
"desc"
,
"nested_path"
:
"related_billboard"
},
})
elif
sort_by
==
TOPIC_SEARCH_SORT
.
VIRT_VOTE_AEC
:
sort_rule
.
append
({
"related_billboard.virt_vote_cnt"
:
{
"order"
:
"asc"
,
"nested_path"
:
"related_billboard"
},
})
elif
sort_by
==
TOPIC_SEARCH_SORT
.
VIRT_VOTE_DESC
:
sort_rule
.
append
({
"related_billboard.virt_vote_cnt"
:
{
"order"
:
"desc"
,
"nested_path"
:
"related_billboard"
},
})
return
sort_rule
@classmethod
...
...
@@ -976,7 +1005,6 @@ class TopicUtils(object):
def
business_topic_ids
(
cls
,
filters
,
nfilters
,
sorts_by
,
offset
=
0
,
size
=
10
,
index_name
=
"topic"
,
filter_online
=
True
):
must
=
cls
.
business_filters
(
filters
,
filter_online
=
filter_online
)
logging
.
info
(
"get must:
%
s"
%
must
)
q
=
{
"query"
:
{
"bool"
:
{
...
...
@@ -1072,6 +1100,24 @@ class TopicUtils(object):
}
}
})
# elif k == "pictorial_id":
# f.append({
# "nested": {
# "path": "related_billboard",
# "query": {
# "bool": {
# "must": [
# {
# "term": {
# "related_billboard.pictorial_id": v
# }
# }
# ]
# }
# }
# }
# })
else
:
if
isinstance
(
v
,
list
):
...
...
search/views/group.py
View file @
8a589d3c
...
...
@@ -59,7 +59,8 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
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
[]
pictorial_ids_list
=
GroupUtils
.
get_hot_pictorial_recommend_result_list
(
offset
,
size
,
es_cli_obj
,
attention_tag_list
)
pictorial_ids_list
=
GroupUtils
.
get_hot_pictorial_recommend_result_list
(
offset
,
size
,
es_cli_obj
,
attention_tag_list
)
return
{
"pictorial_recommend_ids"
:
pictorial_ids_list
}
elif
sort_type
==
GroupSortTypes
.
ATTENTION_RECOMMEND
:
...
...
@@ -251,34 +252,39 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
"query"
:
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"pictorial_id"
:
pictorial_id
}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
#
{
#
"nested": {
#
"path": "related_billboard",
#
"query": {
#
"bool": {
#
"must": [
#
{
#
"term": {
# "
pictorial_id": pictorial_id
#
}
#
}
#
]
#
}
#
}
#
}
#
}
{
"nested"
:
{
"path"
:
"related_billboard"
,
"query"
:
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"related_billboard.
pictorial_id"
:
pictorial_id
}
}
]
}
}
}
}
]
}
},
"sort"
:
[
{
"total_vote_num"
:
{
"order"
:
"desc"
}},
{
"related_billboard.total_vote_cnt"
:
{
"order"
:
"desc"
,
# "mode": "min",
"nested_path"
:
"related_billboard"
}},
{
"create_time"
:
{
"order"
:
"desc"
}}
]
}
logging
.
info
(
"get qqqqqq:
%
s"
%
q
)
pict_pictorial_ids_list
=
[]
# 获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
...
...
trans2es/mapping/topic.json
View file @
8a589d3c
...
...
@@ -8,18 +8,18 @@
"vote_num"
:{
"type"
:
"long"
},
"total_vote_num"
:{
"type"
:
"long"
},
"reply_num"
:{
"type"
:
"long"
},
"name"
:{
"type"
:
"text"
,
"analyzer"
:
"
gm_default_index"
,
"search_analyzer"
:
"gm_default_index
"
},
"description"
:{
"type"
:
"text"
,
"analyzer"
:
"
gm_default_index"
,
"search_analyzer"
:
"gm_default_index
"
},
"content"
:{
"type"
:
"text"
,
"analyzer"
:
"
gm_default_index"
,
"search_analyzer"
:
"gm_default_index
"
},
"name"
:{
"type"
:
"text"
,
"analyzer"
:
"
keyword"
,
"search_analyzer"
:
"keyword
"
},
"description"
:{
"type"
:
"text"
,
"analyzer"
:
"
keyword"
,
"search_analyzer"
:
"keyword
"
},
"content"
:{
"type"
:
"text"
,
"analyzer"
:
"
keyword"
,
"search_analyzer"
:
"keyword
"
},
"content_level"
:{
"type"
:
"text"
},
"user_id"
:{
"type"
:
"long"
},
"user_nick_name"
:{
"type"
:
"text"
,
"analyzer"
:
"
gm_default_index"
,
"search_analyzer"
:
"gm_default_index
"
},
//帖子用户名
"user_nick_name"
:{
"type"
:
"text"
,
"analyzer"
:
"
keyword"
,
"search_analyzer"
:
"keyword
"
},
//帖子用户名
"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
"
},
"tag_name_list"
:{
"type"
:
"text"
,
"analyzer"
:
"
keyword"
,
"search_analyzer"
:
"keyword
"
},
"share_num"
:{
"type"
:
"long"
},
"pick_id_list"
:{
"type"
:
"long"
},
"offline_score"
:{
"type"
:
"double"
},
//离线算分
...
...
@@ -50,8 +50,8 @@
"pictorial_id"
:{
"type"
:
"long"
},
//所在组ID
"pictorial_name"
:{
//
所在组名称
"type"
:
"text"
,
"analyzer"
:
"
gm_default_index
"
,
"search_analyzer"
:
"
gm_default_index
"
"analyzer"
:
"
keyword
"
,
"search_analyzer"
:
"
keyword
"
},
"is_excellent"
:{
"type"
:
"long"
},
"is_operation_home_recommend"
:
{
"type"
:
"boolean"
},
//是否首页运营推荐
...
...
@@ -61,7 +61,8 @@
"properties"
:{
"pictorial_id"
:{
"type"
:
"long"
},
"real_vote_cnt"
:{
"type"
:
"long"
},
"virt_vote_cnt"
:{
"type"
:
"long"
}
"virt_vote_cnt"
:{
"type"
:
"long"
},
"total_vote_cnt"
:{
"type"
:
"long"
}
}
}
}
...
...
trans2es/models/topic.py
View file @
8a589d3c
...
...
@@ -113,9 +113,15 @@ class Topic(models.Model):
def
get_pictorial_id
(
self
):
try
:
pictorial_id_list
=
[]
logging
.
info
(
"get pictorial_id:
%
s"
%
self
.
id
)
pictorial_id
=
PictorialTopic
.
objects
.
filter
(
topic_id
=
self
.
id
)
.
values_list
(
"pictorial_id"
,
flat
=
True
)
logging
.
info
(
"get pictorial_id:
%
s"
%
pictorial_id_list
)
for
i
in
pictorial_id
:
pictorial_id_list
.
append
(
i
)
logging
.
info
(
"get pictorial_id:
%
s"
%
pictorial_id_list
)
return
pictorial_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
@@ -270,16 +276,16 @@ class Topic(models.Model):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
0.0
def
get_related_billboard
(
self
):
try
:
related_billboard_list
=
list
()
query_results
=
TopicBillBoard
.
objects
.
filter
(
id
=
self
.
id
)
query_results
=
TopicBillBoard
.
objects
.
filter
(
topic_
id
=
self
.
id
)
for
items
in
query_results
:
total_vote_cnt
=
int
(
items
.
virt_vote_cnt
)
+
int
(
items
.
real_vote_cnt
)
related_billboard_list
.
append
({
"pictorial_id"
:
items
.
pictorial_id
,
"real_vote_cnt"
:
items
.
real_vote_cnt
,
"virt_vote_cnt"
:
items
.
virt_vote_cnt
})
"virt_vote_cnt"
:
items
.
virt_vote_cnt
,
"total_vote_cnt"
:
total_vote_cnt
})
logging
.
info
(
"product_brand_info"
%
related_billboard_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