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
钟尚武
physical
Commits
e2a54bc2
Commit
e2a54bc2
authored
May 30, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完全匹配用户昵称
parent
fbf58695
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
user.py
search/views/user.py
+23
-3
user_transfer.py
trans2es/utils/user_transfer.py
+1
-0
No files found.
search/views/user.py
View file @
e2a54bc2
...
@@ -106,6 +106,25 @@ def search_user(query="", offset=0, size=10):
...
@@ -106,6 +106,25 @@ def search_user(query="", offset=0, size=10):
"""
"""
try
:
try
:
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
{}
# 先获取完全匹配的用户ID
sheer_user_id
=
[]
q
[
"query"
]
=
{
"term"
:
{
"nick_name_pre"
:
query
}
}
# que = {"query": {"term": {"nick_name_pre": query}}}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
0
,
10
)
res
=
result_dict
[
"hits"
]
if
len
(
res
)
>
0
:
user_id
=
[
item
[
"_source"
][
"user_id"
]
for
item
in
res
]
sheer_user_id
.
append
(
user_id
)
logging
.
info
(
"get res:
%
s"
%
res
)
# 获取模糊匹配的用户ID
multi_match
=
{
multi_match
=
{
"fields"
:
[
"nick_name"
],
"fields"
:
[
"nick_name"
],
...
@@ -138,16 +157,17 @@ def search_user(query="", offset=0, size=10):
...
@@ -138,16 +157,17 @@ def search_user(query="", offset=0, size=10):
}
}
logging
.
info
(
"get q:
%
s"
%
q
)
logging
.
info
(
"get q:
%
s"
%
q
)
es_cli_obj
=
ESPerform
.
get_cli
()
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
,
size
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
,
size
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
search_user_id
=
[]
res
=
result_dict
[
"hits"
]
res
=
result_dict
[
"hits"
]
if
len
(
res
)
>
0
:
if
len
(
res
)
>
0
:
user_id
=
[
item
[
"_source"
][
"user_id"
]
for
item
in
res
]
search_user_id
=
[
item
[
"_source"
][
"user_id"
]
for
item
in
res
]
return
{
"search_user_id"
:
user_id
}
return
{
"sheer_user_id"
:
sheer_user_id
,
"search_user_id"
:
search_user_id
}
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
trans2es/utils/user_transfer.py
View file @
e2a54bc2
...
@@ -41,6 +41,7 @@ class UserTransfer(object):
...
@@ -41,6 +41,7 @@ class UserTransfer(object):
res
[
"id"
]
=
instance
.
id
res
[
"id"
]
=
instance
.
id
res
[
"user_id"
]
=
instance
.
user_id
res
[
"user_id"
]
=
instance
.
user_id
res
[
"nick_name"
]
=
instance
.
nick_name
res
[
"nick_name"
]
=
instance
.
nick_name
res
[
"nick_name_pre"
]
=
instance
.
nick_name
res
[
"profile_pic"
]
=
instance
.
profile_pic
res
[
"profile_pic"
]
=
instance
.
profile_pic
res
[
"gender"
]
=
instance
.
gender
res
[
"gender"
]
=
instance
.
gender
res
[
"city_id"
]
=
instance
.
city_id
res
[
"city_id"
]
=
instance
.
city_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