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
04a8bba6
Commit
04a8bba6
authored
Apr 24, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'test'
Master See merge request
!303
parents
6a1d7980
1fdce0cf
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
3 deletions
+75
-3
es.py
libs/es.py
+20
-2
topic.py
search/utils/topic.py
+1
-1
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 @
04a8bba6
...
@@ -18,13 +18,14 @@ class ESPerform(object):
...
@@ -18,13 +18,14 @@ class ESPerform(object):
index_prefix
=
settings
.
ES_INDEX_PREFIX
index_prefix
=
settings
.
ES_INDEX_PREFIX
@classmethod
@classmethod
def
get_cli
(
cls
):
def
get_cli
(
cls
,
cli_info
=
None
):
try
:
try
:
init_args
=
{
init_args
=
{
'sniff_on_start'
:
False
,
'sniff_on_start'
:
False
,
'sniff_on_connection_fail'
:
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
return
cls
.
cli_obj
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
@@ -230,6 +231,23 @@ class ESPerform(object):
...
@@ -230,6 +231,23 @@ class ESPerform(object):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"total_count"
:
0
,
"hits"
:
[]}
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
@classmethod
def
if_es_node_load_high
(
cls
,
es_cli
):
def
if_es_node_load_high
(
cls
,
es_cli
):
try
:
try
:
...
...
search/utils/topic.py
View file @
04a8bba6
...
@@ -181,7 +181,7 @@ class TopicUtils(object):
...
@@ -181,7 +181,7 @@ class TopicUtils(object):
"content_level"
:
6
"content_level"
:
6
}
}
},
},
"weight"
:
2
00
"weight"
:
10
00
}
}
]
]
...
...
search/views/tag.py
View file @
04a8bba6
...
@@ -12,6 +12,7 @@ from libs.cache import redis_client
...
@@ -12,6 +12,7 @@ from libs.cache import redis_client
from
search.utils.common
import
*
from
search.utils.common
import
*
from
trans2es.models.tag
import
TopicTag
,
AccountUserTag
,
CommunityTagFollow
,
Tag
from
trans2es.models.tag
import
TopicTag
,
AccountUserTag
,
CommunityTagFollow
,
Tag
import
time
import
time
from
django.conf
import
settings
def
get_highlight
(
fields
=
[]):
def
get_highlight
(
fields
=
[]):
...
@@ -150,3 +151,28 @@ def choice_push_tag(device_id, user_id):
...
@@ -150,3 +151,28 @@ def choice_push_tag(device_id, user_id):
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"tag_list"
:
[]}
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 @
04a8bba6
{
"dynamic"
:
"strict"
,
"properties"
:
{
"name"
:{
"type"
:
"keyword"
}
}
}
\ No newline at end of file
trans2es/type_info.py
View file @
04a8bba6
...
@@ -466,6 +466,16 @@ def get_type_info_map():
...
@@ -466,6 +466,16 @@ def get_type_info_map():
round_insert_chunk_size
=
5
,
round_insert_chunk_size
=
5
,
round_insert_period
=
2
,
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
(
TypeInfo
(
name
=
'contrast_similar'
,
# facesimilar
name
=
'contrast_similar'
,
# facesimilar
type
=
'contrast_similar'
,
type
=
'contrast_similar'
,
...
...
trans2es/utils/tag_transfer.py
View file @
04a8bba6
...
@@ -16,6 +16,17 @@ from django.conf import settings
...
@@ -16,6 +16,17 @@ from django.conf import settings
class
TagTransfer
(
object
):
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
@classmethod
def
get_tag_data
(
cls
,
instance
):
def
get_tag_data
(
cls
,
instance
):
try
:
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