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
8a991816
Commit
8a991816
authored
Nov 26, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
6e1cf878
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
9 deletions
+119
-9
es.py
libs/es.py
+28
-0
__init__.py
search/utils/__init__.py
+0
-0
topic.py
search/utils/topic.py
+35
-0
topic.py
search/views/topic.py
+5
-3
user.json
trans2es/mapping/user.json
+21
-3
user.py
trans2es/models/user.py
+30
-3
No files found.
libs/es.py
View file @
8a991816
...
...
@@ -148,3 +148,30 @@ class ESPerform(object):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
@classmethod
def
get_search_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
,
offset
=
0
,
size
=
10
,
auto_create_index
=
False
,
doc_type
=
"_doc"
):
try
:
assert
(
es_cli
is
not
None
)
official_index_name
=
cls
.
get_official_index_name
(
sub_index_name
,
"read"
)
index_exists
=
es_cli
.
indices
.
exists
(
official_index_name
)
if
not
index_exists
:
if
not
auto_create_index
:
logging
.
error
(
"index:
%
s is not existing,get_search_results error!"
%
official_index_name
)
return
None
else
:
cls
.
create_index
(
es_cli
,
sub_index_name
)
cls
.
put_index_mapping
(
es_cli
,
sub_index_name
)
res
=
es_cli
.
search
(
index
=
official_index_name
,
doc_type
=
doc_type
,
body
=
query_body
,
from_
=
offset
,
size
=
size
)
result_dict
=
{
"total_count"
:
res
[
"hits"
][
"total"
],
"hits"
:
res
[
"hits"
][
"hits"
]
}
return
result_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
None
\ No newline at end of file
search/utils/__init__.py
0 → 100644
View file @
8a991816
search/utils/topic.py
0 → 100644
View file @
8a991816
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
logging
import
traceback
from
libs.es
import
ESPerform
class
TopicUtils
(
object
):
@classmethod
def
get_related_user_info
(
cls
,
user_id
,
offset
=
0
,
size
=
10
):
"""
:remark:获取指定用户相关用户列表
:param user_id:
:param offset:
:param size:
:return:
"""
try
:
q
=
dict
()
q
[
"query"
]
=
{
"user_id"
:
user_id
}
q
[
"_souce"
]
=
[
"attention_user_id_list"
,
"pick_user_id_list"
,
"same_group_user_id_list"
]
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"topic"
,
q
,
offset
,
size
)
return
result_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
None
search/views/topic.py
View file @
8a991816
...
...
@@ -4,12 +4,11 @@
from
gm_rpcd.all
import
bind
import
logging
import
traceback
from
search.utils.topic
import
TopicUtils
@bind
(
"physical/search/home_recommend"
)
def
home_recommend
(
user_id
=-
1
):
def
home_recommend
(
user_id
=-
1
,
offset
=
0
,
size
=
10
):
"""
:remark:首页推荐,目前只推荐日记
:return:
...
...
@@ -23,6 +22,9 @@ def home_recommend(user_id=-1):
# 马甲账号集合
vest_account_list
=
list
()
result_dict
=
TopicUtils
.
get_related_user_info
(
user_id
,
offset
,
size
)
q
=
dict
()
q
[
"filter"
]
=
{
"range"
:{
"content_level"
:{
"gte"
:
3
,
"lte"
:
5
}}
...
...
trans2es/mapping/user.json
View file @
8a991816
...
...
@@ -10,9 +10,27 @@
"tag_list"
:{
"type"
:
"text"
},
//标签属性
"city_id"
:{
"type"
:
"long"
},
"country_id"
:{
"type"
:
"long"
},
"attention_user_id_list"
:{
"type"
:
"long"
},
//关注用户列表
"pick_user_id_list"
:{
"type"
:
"long"
},
//pick用户列表
"same_group_user_id_list"
:{
"type"
:
"text"
},
//同组用户列表
"attention_user_id_list"
:{
//关注用户列表
"type"
:
"nested"
,
"properties"
:{
"user_id"
:{
"type"
:
"long"
},
"country_id"
:{
"type"
:
"long"
}
}
},
"pick_user_id_list"
:{
//pick用户列表
"type"
:
"nested"
,
"properties"
:{
"user_id"
:{
"type"
:
"long"
},
"country_id"
:{
"type"
:
"long"
}
}
},
"same_group_user_id_list"
:{
//同组用户列表
"type"
:
"nested"
,
"properties"
:{
"user_id"
:{
"type"
:
"long"
},
"country_id"
:{
"type"
:
"long"
}
}
},
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
}
}
...
...
trans2es/models/user.py
View file @
8a991816
...
...
@@ -36,7 +36,16 @@ class User(models.Model):
for
user_follow
in
user_follows
:
follow_user_id_list
.
append
(
user_follow
.
follow_id
)
return
follow_user_id_list
follow_user_detail_list
=
list
()
sql_data_list
=
self
.
objects
.
get
(
id__in
=
follow_user_id_list
)
for
detail_data
in
sql_data_list
:
item
=
{
"usr_id"
:
detail_data
.
user_id
,
"country_id"
:
detail_data
.
country_id
}
follow_user_detail_list
.
append
(
item
)
return
follow_user_detail_list
def
get_pick_user_id_list
(
self
):
pick_user_id_list
=
list
()
...
...
@@ -44,7 +53,16 @@ class User(models.Model):
for
user_pick
in
user_picks
:
pick_user_id_list
.
append
(
user_pick
.
pickuser_id
)
return
pick_user_id_list
pick_user_detail_list
=
list
()
sql_data_list
=
self
.
objects
.
get
(
id__in
=
pick_user_id_list
)
for
detail_data
in
sql_data_list
:
item
=
{
"usr_id"
:
detail_data
.
user_id
,
"country_id"
:
detail_data
.
country_id
}
pick_user_detail_list
.
append
(
item
)
return
pick_user_detail_list
def
get_same_group_user_id_list
(
self
):
same_group_user_id_list
=
list
()
...
...
@@ -55,6 +73,15 @@ class User(models.Model):
for
user_items_list
in
user_items_list
:
same_group_user_id_list
.
append
(
user_items_list
.
user_id
)
return
same_group_user_id_list
same_group_detail_list
=
list
()
sql_data_list
=
self
.
objects
.
get
(
id__in
=
same_group_user_id_list
)
for
detail_data
in
sql_data_list
:
item
=
{
"usr_id"
:
detail_data
.
user_id
,
"country_id"
:
detail_data
.
country_id
}
same_group_detail_list
.
append
(
item
)
return
same_group_detail_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