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
da1d0d49
Commit
da1d0d49
authored
Jan 03, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
b63d9b61
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
18 deletions
+57
-18
common.py
search/utils/common.py
+5
-0
topic.py
search/utils/topic.py
+10
-4
topic.py
search/views/topic.py
+4
-4
topic.json
trans2es/mapping/topic.json
+1
-0
topic.py
trans2es/models/topic.py
+36
-10
topic_transfer.py
trans2es/utils/topic_transfer.py
+1
-0
No files found.
search/utils/common.py
View file @
da1d0d49
...
@@ -26,7 +26,12 @@ class TopicDocumentField(object):
...
@@ -26,7 +26,12 @@ class TopicDocumentField(object):
IS_ONLINE
=
"is_online"
,
IS_ONLINE
=
"is_online"
,
TAG_LIST
=
"tag_list"
TAG_LIST
=
"tag_list"
class
TopicPageType
(
object
):
# 首页推荐
HOME_RECOMMEND
=
0
# 发现页面
FIND_PAGE
=
1
def
time_consuming_decorator
(
func
):
def
time_consuming_decorator
(
func
):
def
time_consuming
(
*
args
,
**
kwargs
):
def
time_consuming
(
*
args
,
**
kwargs
):
...
...
search/utils/topic.py
View file @
da1d0d49
...
@@ -6,6 +6,8 @@ import traceback
...
@@ -6,6 +6,8 @@ import traceback
import
json
import
json
from
libs.es
import
ESPerform
from
libs.es
import
ESPerform
from
.common
import
TopicDocumentField
from
.common
import
TopicDocumentField
from
search.utils.common
import
*
class
TopicUtils
(
object
):
class
TopicUtils
(
object
):
...
@@ -88,7 +90,7 @@ class TopicUtils(object):
...
@@ -88,7 +90,7 @@ class TopicUtils(object):
return
[]
return
[]
@classmethod
@classmethod
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
query
=
None
):
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
"""
"""
:需增加打散逻辑
:需增加打散逻辑
:remark:获取首页推荐帖子列表
:remark:获取首页推荐帖子列表
...
@@ -172,12 +174,16 @@ class TopicUtils(object):
...
@@ -172,12 +174,16 @@ class TopicUtils(object):
}
}
)
)
low_content_level
=
4
if
query_type
==
TopicPageType
.
FIND_PAGE
else
3
query_function_score
=
{
query_function_score
=
{
"query"
:
{
"query"
:
{
"bool"
:
{
"bool"
:
{
"must"
:
{
"must"
:
[
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
5
}}
{
"range"
:
{
"content_level"
:
{
"gte"
:
low_content_level
,
"lte"
:
5
}}},
}
{
"term"
:
{
"has_image"
:
True
}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}}
]
}
}
},
},
"score_mode"
:
"sum"
,
"score_mode"
:
"sum"
,
...
...
search/views/topic.py
View file @
da1d0d49
...
@@ -12,7 +12,7 @@ from libs.cache import redis_client
...
@@ -12,7 +12,7 @@ from libs.cache import redis_client
from
search.utils.common
import
*
from
search.utils.common
import
*
def
get_home_recommend_topic_ids
(
user_id
,
session_id
,
offset
,
size
,
query
=
None
):
def
get_home_recommend_topic_ids
(
user_id
,
session_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
try
:
try
:
if
query
is
None
:
if
query
is
None
:
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":session_id:"
+
session_id
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":session_id:"
+
session_id
...
@@ -27,7 +27,7 @@ def get_home_recommend_topic_ids(user_id,session_id,offset,size,query=None):
...
@@ -27,7 +27,7 @@ def get_home_recommend_topic_ids(user_id,session_id,offset,size,query=None):
last_offset_num
=
int
(
redis_field_val_list
[
0
])
if
redis_field_val_list
[
0
]
else
-
1
last_offset_num
=
int
(
redis_field_val_list
[
0
])
if
redis_field_val_list
[
0
]
else
-
1
recommend_topic_ids
=
[]
recommend_topic_ids
=
[]
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
*
size
,
query
)
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
*
size
,
query
,
query_type
=
query_type
)
have_read_group_id_set
=
set
()
have_read_group_id_set
=
set
()
unread_topic_id_list
=
list
()
unread_topic_id_list
=
list
()
have_read_topic_id_set
=
set
()
have_read_topic_id_set
=
set
()
...
@@ -92,7 +92,7 @@ def get_home_recommend_topic_ids(user_id,session_id,offset,size,query=None):
...
@@ -92,7 +92,7 @@ def get_home_recommend_topic_ids(user_id,session_id,offset,size,query=None):
@bind
(
"physical/search/home_recommend"
)
@bind
(
"physical/search/home_recommend"
)
def
home_recommend
(
session_id
=
""
,
user_id
=-
1
,
offset
=
0
,
size
=
10
):
def
home_recommend
(
session_id
=
""
,
user_id
=-
1
,
offset
=
0
,
size
=
10
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
"""
"""
:remark:首页推荐,目前只推荐日记
:remark:首页推荐,目前只推荐日记
:param session_id:
:param session_id:
...
@@ -107,7 +107,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
...
@@ -107,7 +107,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
if
not
isinstance
(
session_id
,
str
):
if
not
isinstance
(
session_id
,
str
):
session_id
=
""
session_id
=
""
recommend_topic_ids
=
get_home_recommend_topic_ids
(
user_id
,
session_id
,
offset
,
size
)
recommend_topic_ids
=
get_home_recommend_topic_ids
(
user_id
,
session_id
,
offset
,
size
,
query_type
=
query_type
)
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
except
:
except
:
...
...
trans2es/mapping/topic.json
View file @
da1d0d49
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
"pick_id_list"
:{
"type"
:
"long"
},
"pick_id_list"
:{
"type"
:
"long"
},
"offline_score"
:{
"type"
:
"double"
},
//离线算分
"offline_score"
:{
"type"
:
"double"
},
//离线算分
"manual_score"
:{
"type"
:
"double"
},
//人工赋分
"manual_score"
:{
"type"
:
"double"
},
//人工赋分
"has_image"
:{
"type"
:
"boolean"
},
//是否有图
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"create_time_val"
:{
"type"
:
"long"
},
"create_time_val"
:{
"type"
:
"long"
},
...
...
trans2es/models/topic.py
View file @
da1d0d49
...
@@ -27,32 +27,58 @@ class ActionSumAboutTopic(models.Model):
...
@@ -27,32 +27,58 @@ class ActionSumAboutTopic(models.Model):
data_type
=
models
.
IntegerField
(
verbose_name
=
u"动作类型"
)
data_type
=
models
.
IntegerField
(
verbose_name
=
u"动作类型"
)
data_value
=
models
.
BigIntegerField
(
verbose_name
=
u"值"
)
data_value
=
models
.
BigIntegerField
(
verbose_name
=
u"值"
)
class
TopicImage
(
models
.
Model
):
class
Meta
:
verbose_name
=
u'日记图片'
db_table
=
'topic_image'
id
=
models
.
IntegerField
(
verbose_name
=
'日记图片ID'
,
primary_key
=
True
)
topic_id
=
models
.
IntegerField
(
verbose_name
=
u'日记ID'
)
url
=
models
.
CharField
(
verbose_name
=
u'图片URL'
,
max_length
=
300
)
is_online
=
models
.
BooleanField
(
verbose_name
=
'是否上线'
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
'是否删除'
)
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
Topic
(
models
.
Model
):
class
Topic
(
models
.
Model
):
class
Meta
:
class
Meta
:
verbose_name
=
u'日记'
verbose_name
=
u'日记'
db_table
=
'topic'
db_table
=
'topic'
id
=
models
.
IntegerField
(
verbose_name
=
'日记ID'
,
primary_key
=
True
)
id
=
models
.
IntegerField
(
verbose_name
=
u
'日记ID'
,
primary_key
=
True
)
name
=
models
.
CharField
(
verbose_name
=
'日记名称'
,
max_length
=
100
)
name
=
models
.
CharField
(
verbose_name
=
u
'日记名称'
,
max_length
=
100
)
#group_id = models.IntegerField(verbose_name='用户所在组ID',default=-1)
#group_id = models.IntegerField(verbose_name='用户所在组ID',default=-1)
group
=
models
.
ForeignKey
(
group
=
models
.
ForeignKey
(
Group
,
verbose_name
=
u"关联的小组"
,
related_name
=
u"group_topics"
,
null
=
True
,
blank
=
True
,
default
=
None
,
on_delete
=
models
.
CASCADE
)
Group
,
verbose_name
=
u"关联的小组"
,
related_name
=
u"group_topics"
,
null
=
True
,
blank
=
True
,
default
=
None
,
on_delete
=
models
.
CASCADE
)
user_id
=
models
.
IntegerField
(
verbose_name
=
'用户ID'
)
user_id
=
models
.
IntegerField
(
verbose_name
=
u
'用户ID'
)
drop_score
=
models
.
IntegerField
(
verbose_name
=
u'人工赋分'
,
default
=
0
)
drop_score
=
models
.
IntegerField
(
verbose_name
=
u'人工赋分'
,
default
=
0
)
description
=
models
.
CharField
(
verbose_name
=
'日记本描述'
,
max_length
=
200
)
description
=
models
.
CharField
(
verbose_name
=
u
'日记本描述'
,
max_length
=
200
)
content
=
models
.
CharField
(
verbose_name
=
'日记本内容'
,
max_length
=
1000
)
content
=
models
.
CharField
(
verbose_name
=
u
'日记本内容'
,
max_length
=
1000
)
share_num
=
models
.
IntegerField
(
verbose_name
=
''
)
share_num
=
models
.
IntegerField
(
verbose_name
=
''
)
vote_num
=
models
.
IntegerField
(
verbose_name
=
'点赞数'
)
vote_num
=
models
.
IntegerField
(
verbose_name
=
u
'点赞数'
)
reply_num
=
models
.
IntegerField
(
verbose_name
=
'回复数'
)
reply_num
=
models
.
IntegerField
(
verbose_name
=
u
'回复数'
)
cover
=
models
.
CharField
(
verbose_name
=
''
,
max_length
=
200
)
cover
=
models
.
CharField
(
verbose_name
=
''
,
max_length
=
200
)
is_online
=
models
.
BooleanField
(
verbose_name
=
'是否上线'
)
is_online
=
models
.
BooleanField
(
verbose_name
=
u
'是否上线'
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
'是否删除'
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u
'是否删除'
)
content_level
=
models
.
CharField
(
verbose_name
=
'内容等级'
,
max_length
=
3
)
content_level
=
models
.
CharField
(
verbose_name
=
u
'内容等级'
,
max_length
=
3
)
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
))
def
topic_has_image
(
self
):
try
:
has_image
=
False
query_list
=
TopicImage
.
objects
.
filter
(
topic_id
=
self
.
id
,
is_deleted
=
False
,
is_online
=
True
)
if
len
(
query_list
)
>
0
:
has_image
=
True
return
has_image
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
def
get_pick_id_info
(
self
):
def
get_pick_id_info
(
self
):
try
:
try
:
pick_id_list
=
list
()
pick_id_list
=
list
()
...
...
trans2es/utils/topic_transfer.py
View file @
da1d0d49
...
@@ -38,6 +38,7 @@ class TopicTransfer(object):
...
@@ -38,6 +38,7 @@ class TopicTransfer(object):
res
[
"offline_score"
]
=
instance
.
get_topic_offline_score
()
res
[
"offline_score"
]
=
instance
.
get_topic_offline_score
()
res
[
"manual_score"
]
=
instance
.
drop_score
res
[
"manual_score"
]
=
instance
.
drop_score
res
[
"has_image"
]
=
instance
.
topic_has_image
()
create_time
=
instance
.
create_time
create_time
=
instance
.
create_time
tzlc_create_time
=
tzlc
(
create_time
)
tzlc_create_time
=
tzlc
(
create_time
)
...
...
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