Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
physical
Commits
96aa1fa8
Commit
96aa1fa8
authored
May 16, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
05bcb84f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
64 deletions
+35
-64
tasks.py
injection/data_sync/tasks.py
+11
-2
topic.py
search/utils/topic.py
+13
-38
topic.py
search/views/topic.py
+11
-8
topic.py
trans2es/models/topic.py
+0
-16
No files found.
injection/data_sync/tasks.py
View file @
96aa1fa8
...
...
@@ -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
)
...
...
search/utils/topic.py
View file @
96aa1fa8
...
...
@@ -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
):
...
...
@@ -158,14 +160,6 @@ class TopicUtils(object):
q
[
"query"
]
=
dict
()
functions_list
=
[
# {
# "filter": {
# "term": {
# "language_type": 1
# }
# },
# "weight": 60
# },
{
"gauss"
:
{
"create_time"
:
{
...
...
@@ -174,38 +168,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
:
...
...
@@ -221,8 +199,6 @@ class TopicUtils(object):
"query"
:
{
"bool"
:
{
"filter"
:
[
# {"term": {"content_level": 6}},
# {"term": {"has_image":True}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}}
],
...
...
@@ -294,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"
]:
...
...
@@ -318,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"
]
}
...
...
search/views/topic.py
View file @
96aa1fa8
...
...
@@ -49,13 +49,15 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
disable_collpase
=
False
):
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
:
...
...
@@ -96,8 +98,8 @@ 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
)
# cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
# newcursor = cursor + 6
if
len
(
recommend_topic_id_list
)
>
6
:
recommend_topic_list
=
recommend_topic_id_list
[
0
:
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
:
...
...
@@ -120,11 +122,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):
...
...
trans2es/models/topic.py
View file @
96aa1fa8
...
...
@@ -227,10 +227,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 +235,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:马甲账号是否对总分降权?
...
...
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