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
246f4915
Commit
246f4915
authored
Nov 30, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
231c8371
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
79 additions
and
12 deletions
+79
-12
cache.cpython-36.pyc
libs/__pycache__/cache.cpython-36.pyc
+0
-0
es.cpython-36.pyc
libs/__pycache__/es.cpython-36.pyc
+0
-0
table_scan.cpython-36.pyc
libs/__pycache__/table_scan.cpython-36.pyc
+0
-0
tools.cpython-36.pyc
libs/__pycache__/tools.cpython-36.pyc
+0
-0
es.py
libs/es.py
+3
-1
group.py
search/utils/group.py
+45
-3
topic.py
search/utils/topic.py
+1
-1
group.py
search/views/group.py
+12
-0
topic.py
search/views/topic.py
+2
-2
user.json
trans2es/mapping/user.json
+5
-2
user.py
trans2es/models/user.py
+2
-1
user_transfer.py
trans2es/utils/user_transfer.py
+9
-2
No files found.
libs/__pycache__/cache.cpython-36.pyc
0 → 100644
View file @
246f4915
File added
libs/__pycache__/es.cpython-36.pyc
0 → 100644
View file @
246f4915
File added
libs/__pycache__/table_scan.cpython-36.pyc
0 → 100644
View file @
246f4915
File added
libs/__pycache__/tools.cpython-36.pyc
0 → 100644
View file @
246f4915
File added
libs/es.py
View file @
246f4915
...
...
@@ -151,7 +151,7 @@ class ESPerform(object):
@classmethod
def
get_search_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
,
offset
=
0
,
size
=
10
,
auto_create_index
=
False
,
doc_type
=
"_doc"
):
auto_create_index
=
False
,
doc_type
=
"_doc"
,
aggregations_query
=
False
):
try
:
assert
(
es_cli
is
not
None
)
...
...
@@ -170,6 +170,8 @@ class ESPerform(object):
"total_count"
:
res
[
"hits"
][
"total"
],
"hits"
:
res
[
"hits"
][
"hits"
]
}
if
aggregations_query
:
result_dict
[
"aggregations"
]
=
res
[
"aggregations"
]
return
result_dict
except
:
...
...
search/utils/group.py
View file @
246f4915
...
...
@@ -53,7 +53,7 @@ class GroupUtils(object):
def
get_hot_group_recommend_results
(
cls
,
offset
,
size
):
try
:
q
=
dict
()
q
[
"
filter
"
]
=
{
q
[
"
query
"
]
=
{
"bool"
:{
"must"
:{
"is_online"
:
True
...
...
@@ -80,7 +80,7 @@ class GroupUtils(object):
"""
try
:
q
=
dict
()
q
[
"
filter
"
]
=
{
q
[
"
query
"
]
=
{
"bool"
:{
"must"
:{
"is_online"
:
True
,
...
...
@@ -94,9 +94,50 @@ class GroupUtils(object):
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
,
size
)
if
len
(
result_dict
[
"hits"
])
>
0
:
return
result_dict
[
"hits"
][
0
][
"attention_group_id_list"
]
return
result_dict
[
"hits"
][
0
][
"
_source"
][
"
attention_group_id_list"
]
else
:
return
[]
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
get_group_ids_by_aggs
(
cls
,
group_id_list
):
"""
:remark:聚合查询获取小组列表
:param group_id_list:
:return:
"""
try
:
q
=
dict
()
q
[
"size"
]
=
0
q
[
"query"
]
=
{
"terms"
:{
"group_id"
:
group_id_list
}
}
q
[
"aggs"
]
=
{
"group_ids"
:{
"terms"
:{
"field"
:
"group_id"
},
"aggs"
:{
"max_date"
:{
"max"
:{
"field"
:
"update_time_val"
}
}
}
}
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"topic"
,
q
,
aggregations_query
=
True
)
buckets_list
=
result_dict
[
"aggregations"
][
"buckets"
]
sorted_buckets_list
=
sorted
(
buckets_list
,
key
=
lambda
item
:
item
[
"max_date"
][
"value"
],
reverse
=
True
)
sorted_group_id_list
=
[
item
[
"key"
]
for
item
in
sorted_buckets_list
]
return
sorted_group_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
\ No newline at end of file
search/utils/topic.py
View file @
246f4915
...
...
@@ -112,7 +112,7 @@ class TopicUtils(object):
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
0
,
1
)
if
len
(
result_dict
[
"hits"
])
==
0
:
logging
.
error
(
"not find user_id:
%
d in es!"
%
int
(
user_id
))
return
{
"recommend_topic_ids"
:
[]}
return
([],[])
logging
.
info
(
"duan add,result_dict:
%
s"
%
str
(
result_dict
)
.
encode
(
"utf-8"
))
attention_user_info_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_user_id_list"
]
...
...
search/views/group.py
View file @
246f4915
...
...
@@ -49,6 +49,18 @@ def group_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,size=1
attention_group_list
=
GroupUtils
.
get_user_attention_group_list
(
user_id
,
offset
,
size
)
if
len
(
attention_group_list
)
==
0
:
return
{
"group_recommend_ids"
:
[]}
else
:
attention_group_id_list
=
[
item
[
"group_id"
]
for
item
in
attention_group_list
]
sorted_group_ids_list
=
GroupUtils
.
get_group_ids_by_aggs
(
attention_group_id_list
)
group_recommend_ids_list
=
sorted_group_ids_list
if
len
(
group_recommend_ids_list
)
<
size
and
len
(
group_recommend_ids_list
)
<
len
(
attention_group_list
):
sorted_attention_group_list
=
sorted
(
attention_group_list
,
key
=
lambda
item
:
item
[
"update_time_val"
],
reverse
=
False
)
for
item
in
sorted_attention_group_list
:
if
item
[
"group_id"
]
not
in
group_recommend_ids_list
:
group_recommend_ids_list
.
append
(
item
[
"group_id"
])
return
{
"group_recommend_ids"
:
group_recommend_ids_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
search/views/topic.py
View file @
246f4915
...
...
@@ -22,8 +22,8 @@ def home_recommend(user_id=-1,offset=0,size=10):
if
len
(
redis_val_dict
)
>
0
:
group_topic_ids
=
json
.
loads
(
redis_val_dict
[
b
"group_topic_ids"
])
not_group_topic_ids
=
json
.
loads
(
redis_val_dict
[
b
"not_group_topic_ids"
])
group_topic_ids_index
=
redis_val_dict
[
b
"group_topic_ids_index"
]
not_group_topic_ids_index
=
redis_val_dict
[
b
"not_group_topic_ids_index"
]
group_topic_ids_index
=
int
(
redis_val_dict
[
b
"group_topic_ids_index"
])
not_group_topic_ids_index
=
int
(
redis_val_dict
[
b
"not_group_topic_ids_index"
])
if
len
(
group_topic_ids
)
<
(
size
-
1
)
or
len
(
not_group_topic_ids
)
<
1
:
if
len
(
group_topic_ids
)
<
(
size
-
1
):
...
...
trans2es/mapping/user.json
View file @
246f4915
...
...
@@ -35,10 +35,12 @@
"type"
:
"nested"
,
"properties"
:{
"group_id"
:{
"type"
:
"long"
},
"update_time
"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis
"
}
"update_time
_val"
:{
"type"
:
"long
"
}
}
},
"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"
},
"update_time_val"
:{
"type"
:
"long"
}
}
}
\ No newline at end of file
trans2es/models/user.py
View file @
246f4915
...
...
@@ -8,6 +8,7 @@ import logging
from
libs.es
import
ESPerform
from
django.db
import
models
import
datetime
import
time
from
libs.tools
import
tzlc
from
.group_user_role
import
GroupUserRole
...
...
@@ -55,7 +56,7 @@ class User(models.Model):
for
item
in
query_results
:
item_dict
=
{
"group_id"
:
item
.
group_id
,
"update_time
"
:
tzlc
(
item
.
update_time
)
"update_time
_val"
:
time
.
mktime
(
tzlc
(
item
.
update_time
)
.
timetuple
()
)
}
attention_group_id_list
.
append
(
item_dict
)
...
...
trans2es/utils/user_transfer.py
View file @
246f4915
...
...
@@ -4,6 +4,7 @@ import os
import
sys
import
logging
import
traceback
import
time
from
libs.tools
import
tzlc
class
UserTransfer
(
object
):
...
...
@@ -21,8 +22,14 @@ class UserTransfer(object):
res
[
"city_id"
]
=
instance
.
city_id
res
[
"country_id"
]
=
instance
.
country_id
res
[
"is_online"
]
=
instance
.
is_online
res
[
"create_time"
]
=
tzlc
(
instance
.
create_time
)
res
[
"update_time"
]
=
tzlc
(
instance
.
update_time
)
tzlc_create_time
=
tzlc
(
instance
.
create_time
)
res
[
"create_time"
]
=
tzlc_create_time
res
[
"create_time_val"
]
=
int
(
time
.
mktime
(
tzlc_create_time
.
timetuple
()))
tzlc_update_time
=
tzlc
(
instance
.
update_time
)
res
[
"update_time"
]
=
tzlc_update_time
res
[
"update_time_val"
]
=
int
(
time
.
mktime
(
tzlc_update_time
.
timetuple
()))
res
[
"tag_list"
]
=
instance
.
get_user_tag_id_list
()
res
[
"attention_user_id_list"
]
=
instance
.
get_follow_user_id_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