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
1fdce0cf
Commit
1fdce0cf
authored
Apr 24, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
30a542a4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
2 deletions
+74
-2
es.py
libs/es.py
+20
-2
tag.py
search/views/tag.py
+26
-0
tag-name.json
trans2es/mapping/tag-name.json
+7
-0
type_info.py
trans2es/type_info.py
+10
-0
tag_transfer.py
trans2es/utils/tag_transfer.py
+11
-0
No files found.
libs/es.py
View file @
1fdce0cf
...
...
@@ -18,13 +18,14 @@ class ESPerform(object):
index_prefix
=
settings
.
ES_INDEX_PREFIX
@classmethod
def
get_cli
(
cls
):
def
get_cli
(
cls
,
cli_info
=
None
):
try
:
init_args
=
{
'sniff_on_start'
:
False
,
'sniff_on_connection_fail'
:
False
,
}
cls
.
cli_obj
=
Elasticsearch
(
hosts
=
cls
.
cli_info_list
,
**
init_args
)
es_cli_info
=
cli_info
if
cli_info
else
cls
.
cli_info_list
cls
.
cli_obj
=
Elasticsearch
(
hosts
=
es_cli_info
,
**
init_args
)
return
cls
.
cli_obj
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
@@ -230,6 +231,23 @@ class ESPerform(object):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"total_count"
:
0
,
"hits"
:
[]}
@classmethod
def
get_analyze_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
):
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
:
logging
.
error
(
"index:
%
s is not existing,get_search_results error!"
%
official_index_name
)
return
None
res
=
es_cli
.
indices
.
analyze
(
index
=
official_index_name
,
body
=
query_body
)
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
None
@classmethod
def
if_es_node_load_high
(
cls
,
es_cli
):
try
:
...
...
search/views/tag.py
View file @
1fdce0cf
...
...
@@ -12,6 +12,7 @@ from libs.cache import redis_client
from
search.utils.common
import
*
from
trans2es.models.tag
import
TopicTag
,
AccountUserTag
,
CommunityTagFollow
,
Tag
import
time
from
django.conf
import
settings
def
get_highlight
(
fields
=
[]):
...
...
@@ -150,3 +151,28 @@ def choice_push_tag(device_id, user_id):
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"tag_list"
:
[]}
@bind
(
"physical/search/identity_tag_name"
)
def
identity_tag_name
(
topic_content
):
try
:
ret_tag_list
=
list
()
redis_key_name
=
"physical:tag_name_set"
body
=
{
'text'
:
topic_content
,
'analyzer'
:
"gm_default_search"
}
cli_info
=
settings
.
TAG_ES_INFO_LIST
res
=
ESPerform
.
get_analyze_results
(
es_cli
=
ESPerform
.
get_cli
(
cli_info
=
cli_info
),
sub_index_name
=
"tag"
,
query_body
=
body
)
for
item
in
res
[
"tokens"
]:
token_word
=
item
[
"token"
]
is_member
=
redis_client
.
sismember
(
redis_key_name
,
token_word
)
if
is_member
:
ret_tag_list
.
append
(
token_word
)
return
{
"tag_name_list"
:
ret_tag_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"tag_name_list"
:
[]}
trans2es/mapping/tag-name.json
0 → 100644
View file @
1fdce0cf
{
"dynamic"
:
"strict"
,
"properties"
:
{
"name"
:{
"type"
:
"keyword"
}
}
}
\ No newline at end of file
trans2es/type_info.py
View file @
1fdce0cf
...
...
@@ -466,6 +466,16 @@ def get_type_info_map():
round_insert_chunk_size
=
5
,
round_insert_period
=
2
,
),
TypeInfo
(
name
=
"tag-name"
,
# 标签名字
type
=
"tag-name"
,
model
=
tag
.
Tag
,
query_deferred
=
lambda
:
tag
.
Tag
.
objects
.
all
()
.
query
,
get_data_func
=
TagTransfer
.
get_tag_name_data
,
bulk_insert_chunk_size
=
100
,
round_insert_chunk_size
=
5
,
round_insert_period
=
2
,
),
TypeInfo
(
name
=
'contrast_similar'
,
# facesimilar
type
=
'contrast_similar'
,
...
...
trans2es/utils/tag_transfer.py
View file @
1fdce0cf
...
...
@@ -16,6 +16,17 @@ from django.conf import settings
class
TagTransfer
(
object
):
@classmethod
def
get_tag_name_data
(
cls
,
instance
):
try
:
res
=
dict
()
res
[
"name"
]
=
instance
.
name
return
res
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
dict
()
@classmethod
def
get_tag_data
(
cls
,
instance
):
try
:
...
...
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