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
b945e2f5
Commit
b945e2f5
authored
Jul 15, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Plain Diff
add
parents
70c617b6
afa5c366
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
115 additions
and
33 deletions
+115
-33
topic.py
search/utils/topic.py
+18
-14
group.py
search/views/group.py
+69
-1
topic-star.json
trans2es/mapping/topic-star.json
+4
-0
topic-v1.json
trans2es/mapping/topic-v1.json
+4
-0
topic.json
trans2es/mapping/topic.json
+1
-1
topic.py
trans2es/models/topic.py
+4
-4
tag_transfer.py
trans2es/utils/tag_transfer.py
+15
-13
No files found.
search/utils/topic.py
View file @
b945e2f5
...
...
@@ -973,7 +973,18 @@ class TopicUtils(object):
"order"
:
"desc"
},
})
if
sorts_by
==
TOPIC_SEARCH_SORT
.
TOPIC_ADD_TIME
:
sort_rule
.
append
({
"related_billboard.topic_add_createtime"
:
{
"order"
:
"desc"
,
"nested_path"
:
"related_billboard"
,
"nested_filter"
:
{
"term"
:
{
"related_billboard.pictorial_id"
:
pictorial_id
}
}
},
})
elif
isinstance
(
sorts_by
,
list
):
for
sort_by
in
sorts_by
:
if
sort_by
==
TOPIC_SEARCH_SORT
.
ID_AEC
:
...
...
@@ -1068,19 +1079,6 @@ class TopicUtils(object):
},
})
elif
sort_by
==
TOPIC_SEARCH_SORT
.
TOPIC_ADD_TIME
:
sort_rule
.
append
({
"related_billboard.topic_add_createtime"
:
{
"order"
:
"desc"
,
"nested_path"
:
"related_billboard"
,
"nested_filter"
:
{
"term"
:
{
"related_billboard.pictorial_id"
:
pictorial_id
}
}
},
})
logging
.
info
(
"get picotirial:
%
s"
%
sort_rule
)
return
sort_rule
...
...
@@ -1098,6 +1096,12 @@ class TopicUtils(object):
}
}
if
'pictorial_id'
in
filters
.
keys
():
if
sorts_by
:
sorts
=
cls
.
process_sort
(
sorts_by
,
filters
[
"pictorial_id"
])
if
sorts
:
q
[
"sort"
]
=
sorts
else
:
if
sorts_by
:
sorts
=
cls
.
process_sort
(
sorts_by
,
pictorial_id
=
None
)
if
sorts
:
...
...
search/views/group.py
View file @
b945e2f5
...
...
@@ -301,7 +301,7 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
es_cli_obj
=
ESPerform
.
get_cli
()
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
offset
,
size
)
logging
.
info
(
"get pictorial_topic_sort res:
%
s"
%
result_dict
)
#
logging.info("get pictorial_topic_sort res:%s" % result_dict)
for
item
in
result_dict
[
"hits"
]:
topic_id
=
item
[
"_source"
][
"id"
]
...
...
@@ -431,3 +431,71 @@ def process_sort(sorts_by):
logging
.
info
(
"get picotirial:
%
s"
%
sort_rule
)
return
sort_rule
@bind
(
"physical/search/pictorialid_topic"
)
def
pictorial_topic_sort_peoplehot
(
pictorial_id
=-
1
,
user_id
=-
1
,
offset
=
0
,
size
=
10
):
try
:
if
not
isinstance
(
pictorial_id
,
int
):
pictorial_id
=
-
1
results
=
pictorial_topic_sort
(
pictorial_id
=
pictorial_id
,
size
=
100
)
pict_pictorial_ids_list
=
results
[
"pict_pictorial_ids_list"
]
logging
.
info
(
"get pict_pictorial_ids_list res:
%
s"
%
pict_pictorial_ids_list
)
q
=
{
"query"
:
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"term"
:
{
"pictorial_id"
:
pictorial_id
}},
{
"term"
:
{
"user_id"
:
user_id
}}
]
}
},
"sort"
:
[
{
"related_billboard.total_vote_cnt"
:
{
"order"
:
"desc"
,
"nested_path"
:
"related_billboard"
,
"missing"
:
"_last"
,
"nested_filter"
:
{
"term"
:
{
"related_billboard.pictorial_id"
:
pictorial_id
}
}
}},
{
"create_time"
:
{
"order"
:
"desc"
}}
]
}
# 获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
offset
,
size
)
user_pict_pictorial_ids_list
=
[]
for
item
in
result_dict
[
"hits"
]:
topic_id
=
item
[
"_source"
][
"id"
]
user_pict_pictorial_ids_list
.
append
(
topic_id
)
logging
.
info
(
"get user_pict_pictorial_ids_list res:
%
s"
%
user_pict_pictorial_ids_list
)
pictorial_user_topicid_list
=
list
()
for
user_id_topic
in
user_pict_pictorial_ids_list
:
if
user_id_topic
in
pict_pictorial_ids_list
:
topic_sort
=
pict_pictorial_ids_list
.
index
(
user_id_topic
)
pictorial_user_topicid_list
.
append
({
"topic_id"
:
user_id_topic
,
"topic_sort"
:
topic_sort
+
1
})
else
:
index
=
user_pict_pictorial_ids_list
.
index
(
user_id_topic
)
pictorial_user_topicid_list
.
append
({
"topic_id"
:
user_id_topic
,
"topic_sort"
:
100
+
index
})
return
{
"pictorial_user_topicid_list"
:
pictorial_user_topicid_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"pict_pictorial_ids_list"
:
[]}
trans2es/mapping/topic-star.json
View file @
b945e2f5
...
...
@@ -60,6 +60,7 @@
"type"
:
"nested"
,
"properties"
:{
"pictorial_id"
:{
"type"
:
"long"
},
"topic_add_createtime"
:{
"type"
:
"long"
},
"real_vote_cnt"
:{
"type"
:
"long"
},
"virt_vote_cnt"
:{
"type"
:
"long"
},
"total_vote_cnt"
:{
"type"
:
"long"
}
...
...
@@ -67,3 +68,6 @@
}
}
}
trans2es/mapping/topic-v1.json
View file @
b945e2f5
...
...
@@ -60,6 +60,7 @@
"type"
:
"nested"
,
"properties"
:{
"pictorial_id"
:{
"type"
:
"long"
},
"topic_add_createtime"
:{
"type"
:
"long"
},
"real_vote_cnt"
:{
"type"
:
"long"
},
"virt_vote_cnt"
:{
"type"
:
"long"
},
"total_vote_cnt"
:{
"type"
:
"long"
}
...
...
@@ -67,3 +68,6 @@
}
}
}
trans2es/mapping/topic.json
View file @
b945e2f5
...
...
@@ -60,7 +60,7 @@
"type"
:
"nested"
,
"properties"
:{
"pictorial_id"
:{
"type"
:
"long"
},
"topic_add_time"
:{
"type"
:
"long"
},
"topic_add_
create
time"
:{
"type"
:
"long"
},
"real_vote_cnt"
:{
"type"
:
"long"
},
"virt_vote_cnt"
:{
"type"
:
"long"
},
"total_vote_cnt"
:{
"type"
:
"long"
}
...
...
trans2es/models/topic.py
View file @
b945e2f5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
import
time
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
...
...
@@ -281,9 +282,6 @@ class Topic(models.Model):
def
get_related_billboard
(
self
):
try
:
# pictorial_ids = Topic.get_pictorial_id(self)
pictorial_id_list
=
[]
related_billboard_list
=
list
()
pictorials
=
PictorialTopic
.
objects
.
filter
(
topic_id
=
self
.
id
)
.
values
(
"pictorial_id"
,
"create_time"
)
...
...
@@ -293,7 +291,8 @@ class Topic(models.Model):
topic_id
=
self
.
id
)
.
values
()
.
first
()
if
query_result
==
None
:
related_billboard_list
.
append
({
"pictorial_id"
:
pictorial_id
.
get
(
'pictorial_id'
,
None
),
"real_vote_cnt"
:
0
,
related_billboard_list
.
append
(
{
"pictorial_id"
:
pictorial_id
.
get
(
'pictorial_id'
,
None
),
"real_vote_cnt"
:
0
,
"virt_vote_cnt"
:
0
,
"total_vote_cnt"
:
0
,
"topic_add_createtime"
:
int
(
time
.
mktime
(
pictorial_id
.
get
(
"create_time"
,
None
)
.
timetuple
()))})
...
...
@@ -310,6 +309,7 @@ class Topic(models.Model):
return
related_billboard_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
...
...
trans2es/utils/tag_transfer.py
View file @
b945e2f5
...
...
@@ -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
)
...
...
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