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
ff096b2b
Commit
ff096b2b
authored
Dec 20, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request
!59
parents
b0ed4e5c
cac42546
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
246 additions
and
9 deletions
+246
-9
topic.py
search/utils/topic.py
+103
-2
tag.py
search/views/tag.py
+52
-5
topic.py
search/views/topic.py
+26
-0
tag.json
trans2es/mapping/tag.json
+6
-1
topic.json
trans2es/mapping/topic.json
+1
-0
tag.py
trans2es/models/tag.py
+30
-1
topic.py
trans2es/models/topic.py
+1
-0
tag_transfer.py
trans2es/utils/tag_transfer.py
+25
-0
topic_transfer.py
trans2es/utils/topic_transfer.py
+2
-0
No files found.
search/utils/topic.py
View file @
ff096b2b
...
...
@@ -206,9 +206,20 @@ class TopicUtils(object):
q
[
"query"
][
"function_score"
]
=
query_function_score
q
[
"_source"
]
=
{
"include"
:[
"id"
,
"group_id"
]
"include"
:[
"id"
,
"group_id"
,
"offline_score"
]
}
q
[
"sort"
]
=
[
{
"_script"
:{
"type"
:
"number"
,
"script"
:{
"lang"
:
"painless"
,
"source"
:
"_score+params._source.offline_score"
},
"order"
:
"desc"
}
}
]
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
...
...
@@ -323,6 +334,95 @@ class TopicUtils(object):
tag_id_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
TopicDocumentField
.
TAG_LIST
]
return
tag_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
@classmethod
def
get_tag_aggregation_topic_id_list
(
cls
,
user_id
,
tag_id
,
offset
,
size
):
try
:
attention_user_id_list
=
list
()
pick_user_id_list
=
list
()
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
0
,
1
)
if
len
(
result_dict
[
"hits"
])
==
0
:
logging
.
warning
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
else
:
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
]
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
]
functions_list
=
[
{
"gauss"
:
{
"update_time"
:
{
"scale"
:
"1d"
,
"decay"
:
0.5
}
}
}
]
if
len
(
attention_user_id_list
)
>
0
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"terms"
:{
"user_id"
:
attention_user_id_list
}}}},
"weight"
:
3
,
}
)
if
len
(
pick_user_id_list
)
>
0
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"terms"
:{
"user_id"
:
pick_user_id_list
}}}},
"weight"
:
2
}
)
query_function_score
=
{
"query"
:{
"bool"
:{
"must"
:
[
{
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
5
}}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"term"
:
{
"tag_list"
:
tag_id
}}
]
}
},
"score_mode"
:
"sum"
,
"boost_mode"
:
"sum"
,
"functions"
:
functions_list
}
q
=
dict
()
q
[
"query"
]
=
{
"function_score"
:
query_function_score
}
q
[
"_source"
]
=
{
"include"
:[
"id"
,
"group_id"
,
"user_id"
,
"_score"
,
"offline_score"
,
"manual_score"
]
}
q
[
"sort"
]
=
[
{
"_script"
:{
"type"
:
"number"
,
"script"
:{
"lang"
:
"painless"
,
"source"
:
"_score+params._source.offline_score+params._source.manual_score"
},
"order"
:
"desc"
}
}
]
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
return
result_dict
[
"hits"
]
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
\ No newline at end of file
search/views/tag.py
View file @
ff096b2b
...
...
@@ -20,17 +20,29 @@ def get_highlight(fields=[]):
}
return
field_highlight
@bind
(
"physical/search/query_tag"
)
def
query_tag
(
query
,
offset
,
size
):
try
:
q
=
{
"query"
:{
"match"
:{
"name"
:
query
"bool"
:{
"must"
:[
{
"term"
:{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}}
],
"should"
:[
{
"match"
:{
"name"
:
query
}}
],
"minimum_should_match"
:
1
}
},
"_source"
:{
"include"
:[
"id"
,
"name"
]
"sort"
:[
{
"near_new_topic_num"
:{
"order"
:
"desc"
}},
{
'_score'
:
{
"order"
:
"desc"
}}
],
"_source"
:
{
"include"
:
[
"id"
,
"name"
]
}
}
q
[
"highlight"
]
=
get_highlight
([
"name"
])
...
...
@@ -39,7 +51,42 @@ def query_tag(query,offset,size):
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"tag"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
for
hit_item
in
result_dict
[
"hits"
]:
hit_item
[
"_source"
][
"highlight"
]
=
hit_item
[
"highlight"
]
if
"name"
in
hit_item
[
"highlight"
]
and
len
(
hit_item
[
"highlight"
][
"name"
])
>
0
:
hit_item
[
"_source"
][
"highlight"
]
=
hit_item
[
"highlight"
][
"name"
][
0
]
else
:
hit_item
[
"_source"
][
"highlight"
]
=
""
ret_list
.
append
(
hit_item
[
"_source"
])
return
{
"tag_list"
:
ret_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"tag_list"
:
[]}
@bind
(
"physical/search/query_by_tag_type"
)
def
query_by_tag_type
(
tag_type_id
,
offset
,
size
):
try
:
q
=
{
"query"
:{
"bool"
:{
"must"
:[
{
"term"
:{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}}
],
"filter"
:{
"term"
:{
"tag_type"
:
tag_type_id
}}
}
},
"sort"
:[
{
"near_new_topic_num"
:{
"order"
:
"desc"
}}
],
"_source"
:
{
"include"
:
[
"id"
,
"name"
]
}
}
ret_list
=
list
()
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"tag"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
for
hit_item
in
result_dict
[
"hits"
]:
ret_list
.
append
(
hit_item
[
"_source"
])
return
{
"tag_list"
:
ret_list
}
...
...
search/views/topic.py
View file @
ff096b2b
...
...
@@ -167,3 +167,29 @@ def topic_detail_page_recommend(user_id=-1,topic_id=-1,topic_group_id=-1,topic_u
return
{
"recommend_topic_ids"
:
[]}
@bind
(
"physical/search/query_topic_by_tag_aggregation"
)
def
query_topic_by_tag_aggregation
(
user_id
,
tag_id
,
offset
,
size
):
"""
:remark 按标签聚合召回帖子
:param tag_id:
:param offset:
:param size:
:return:
"""
try
:
if
not
user_id
:
user_id
=
-
1
if
not
tag_id
:
tag_id
=
-
1
result_list
=
TopicUtils
.
get_tag_aggregation_topic_id_list
(
user_id
,
tag_id
,
offset
,
size
)
recommend_topic_ids_list
=
list
()
if
len
(
result_list
)
>
0
:
recommend_topic_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_list
]
return
{
"recommend_topic_id"
:
recommend_topic_ids_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"recommend_topic_id"
:
[]}
trans2es/mapping/tag.json
View file @
ff096b2b
...
...
@@ -3,6 +3,10 @@
"properties"
:
{
"id"
:{
"type"
:
"long"
},
"suggest"
:{
"type"
:
"completion"
},
"name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"standard"
}
"name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"tag_type"
:{
"type"
:
"long"
},
"is_online"
:{
"type"
:
"boolean"
},
//上线
"is_deleted"
:{
"type"
:
"boolean"
},
"near_new_topic_num"
:{
"type"
:
"long"
,
"store"
:
true
}
}
}
\ No newline at end of file
trans2es/mapping/topic.json
View file @
ff096b2b
...
...
@@ -17,6 +17,7 @@
"share_num"
:{
"type"
:
"long"
},
"pick_id_list"
:{
"type"
:
"long"
},
"offline_score"
:{
"type"
:
"double"
},
//离线算分
"manual_score"
:{
"type"
:
"double"
},
//人工赋分
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"create_time_val"
:{
"type"
:
"long"
},
...
...
trans2es/models/tag.py
View file @
ff096b2b
...
...
@@ -21,7 +21,6 @@ class TopicTag(models.Model):
is_online
=
models
.
BooleanField
(
verbose_name
=
u"是否在线"
)
class
AccountUserTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"用户标签"
...
...
@@ -42,8 +41,38 @@ class Tag(models.Model):
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
)
description
=
models
.
TextField
(
verbose_name
=
u"标签描述"
)
icon_url
=
models
.
CharField
(
verbose_name
=
u"icon_url"
,
max_length
=
120
)
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"
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
))
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"
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
))
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'更新时间'
,
default
=
datetime
.
datetime
.
fromtimestamp
(
0
))
trans2es/models/topic.py
View file @
ff096b2b
...
...
@@ -39,6 +39,7 @@ class Topic(models.Model):
group
=
models
.
ForeignKey
(
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'
)
drop_score
=
models
.
IntegerField
(
verbose_name
=
u'人工赋分'
)
description
=
models
.
CharField
(
verbose_name
=
'日记本描述'
,
max_length
=
200
)
content
=
models
.
CharField
(
verbose_name
=
'日记本内容'
,
max_length
=
1000
)
share_num
=
models
.
IntegerField
(
verbose_name
=
''
)
...
...
trans2es/utils/tag_transfer.py
View file @
ff096b2b
...
...
@@ -5,6 +5,9 @@ import sys
import
logging
import
traceback
from
libs.tools
import
tzlc
from
trans2es.models.topic
import
Topic
from
trans2es.models.tag
import
TopicTag
,
CommunityTagType
,
CommunityTagTypeRelation
import
datetime
class
TagTransfer
(
object
):
...
...
@@ -16,6 +19,28 @@ class TagTransfer(object):
res
[
"id"
]
=
instance
.
id
res
[
"suggest"
]
=
instance
.
name
res
[
"name"
]
=
instance
.
name
res
[
"is_online"
]
=
instance
.
is_online
res
[
"is_deleted"
]
=
instance
.
is_deleted
res
[
"near_new_topic_num"
]
=
0
if
instance
.
is_online
==
True
and
instance
.
is_deleted
==
False
:
topic_id_list
=
list
()
sql_result_list
=
TopicTag
.
objects
.
filter
(
tag_id
=
instance
.
id
)
.
values_list
(
"topic_id"
,
flat
=
True
)
for
item_id
in
sql_result_list
:
topic_id_list
.
append
(
item_id
)
time_base_val
=
datetime
.
datetime
.
strftime
(
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
-
7
),
"
%
Y-
%
m-
%
d"
)
topic_num
=
Topic
.
objects
.
filter
(
id__in
=
topic_id_list
,
create_time__gte
=
time_base_val
)
.
count
()
res
[
"near_new_topic_num"
]
=
topic_num
tag_type_sql_list
=
CommunityTagTypeRelation
.
objects
.
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
)
res
[
"tag_type"
]
=
tag_type_list
return
res
except
:
...
...
trans2es/utils/topic_transfer.py
View file @
ff096b2b
...
...
@@ -17,6 +17,7 @@ class TopicTransfer(object):
res
[
"id"
]
=
instance
.
id
res
[
"is_online"
]
=
instance
.
is_online
res
[
"is_deleted"
]
=
instance
.
is_deleted
res
[
"vote_num"
]
=
instance
.
vote_num
res
[
"reply_num"
]
=
instance
.
reply_num
res
[
"name"
]
=
instance
.
name
...
...
@@ -36,6 +37,7 @@ class TopicTransfer(object):
res
[
"tag_name_list"
]
=
instance
.
get_tag_name_list
(
res
[
"tag_list"
])
res
[
"offline_score"
]
=
instance
.
get_topic_offline_score
()
res
[
"manual_score"
]
=
instance
.
drop_score
create_time
=
instance
.
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