Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
search_tips
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
rank
search_tips
Commits
3d6276c0
Commit
3d6276c0
authored
Jan 30, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
ca91e80d
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
149 additions
and
23 deletions
+149
-23
auto_tips.py
search/view/auto_tips.py
+5
-8
words_utils.py
trans2es/commons/words_utils.py
+43
-0
wordresemble.py
trans2es/models/wordresemble.py
+40
-0
type_info.py
trans2es/type_info.py
+13
-1
brandwiki_transfer.py
trans2es/utils/brandwiki_transfer.py
+2
-2
collectwiki_transfer.py
trans2es/utils/collectwiki_transfer.py
+2
-2
doctor_transfer.py
trans2es/utils/doctor_transfer.py
+2
-2
hospital_transfer.py
trans2es/utils/hospital_transfer.py
+2
-2
itemwiki_transfer.py
trans2es/utils/itemwiki_transfer.py
+2
-2
productwiki_transfer.py
trans2es/utils/productwiki_transfer.py
+2
-2
tag_transfer.py
trans2es/utils/tag_transfer.py
+2
-2
wordresemble.py
trans2es/utils/wordresemble.py
+34
-0
No files found.
search/view/auto_tips.py
View file @
3d6276c0
...
...
@@ -14,7 +14,7 @@ from search.utils.auto_tips import get_suggest_tips
@bind
(
"search_tips/search/auto_complete_query"
)
def
auto_complete_query
(
q
):
def
auto_complete_query
(
q
,
lat
,
lng
):
try
:
"""auto complate words/tags/doctors etc.
...
...
@@ -29,15 +29,12 @@ def auto_complete_query(q):
# if not q:
# return json_http_response({'error': 0, 'data': []})
data
=
get_suggest_tips
(
q
)
data
=
get_suggest_tips
(
q
,
float
(
lat
),
float
(
lng
)
)
result
=
{
'error'
:
0
,
'data'
:
data
,
}
return
{
"data"
:
data
}
return
{
"tips_list"
:
data
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"
data
"
:[]}
return
{
"
tips_list
"
:[]}
trans2es/commons/words_utils.py
View file @
3d6276c0
...
...
@@ -163,3 +163,46 @@ class QueryWordAttr(object):
return
0
from
gm_rpcd.all
import
bind
from
libs.cache
import
redis_client
import
base64
from
gm_types.doris
import
MIND_TYPE
QUERY_KEY
=
"query:{}:set"
LABEL_VALUE
=
{
MIND_TYPE
.
PROJECT
:
6
,
MIND_TYPE
.
BRAND
:
5
,
MIND_TYPE
.
HOSPITAL
:
4
,
MIND_TYPE
.
DOCTOR
:
3
,
MIND_TYPE
.
AREA
:
2
,
MIND_TYPE
.
USER
:
1
,
MIND_TYPE
.
UNKNOWN
:
0
}
QUERY_WORD_LABEL_NEED_MODIFIED
=
{
u"玻尿酸"
:
MIND_TYPE
.
PROJECT
,
u"鼻"
:
MIND_TYPE
.
PROJECT
,
u"眼"
:
MIND_TYPE
.
PROJECT
,
u"嘴"
:
MIND_TYPE
.
PROJECT
,
u"脱毛"
:
MIND_TYPE
.
PROJECT
}
def
label_key
(
label
):
return
LABEL_VALUE
.
get
(
label
)
def
get_tips_word_type
(
query
=
''
):
query_base64
=
base64
.
b64encode
(
query
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
key
=
QUERY_KEY
.
format
(
query_base64
)
labels
=
list
(
map
(
lambda
x
:
x
.
decode
(
"utf8"
),
list
(
redis_client
.
smembers
(
key
))))
labels
.
append
(
MIND_TYPE
.
UNKNOWN
)
if
query
in
QUERY_WORD_LABEL_NEED_MODIFIED
:
labels
.
append
(
MIND_TYPE
.
PROJECT
)
labels
.
sort
(
key
=
label_key
,
reverse
=
True
)
return
labels
[
0
]
trans2es/models/wordresemble.py
0 → 100644
View file @
3d6276c0
# coding=utf8
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
import
operator
from
django.db
import
models
from
django.db.models
import
Q
from
django.db
import
transaction
import
logging
import
traceback
from
gm_types.gaia
import
TAG_ALERT_TYPE
from
django.utils
import
timezone
from
gm_upload
import
IMG_TYPE
,
ImgUrlField
from
gm_types.gaia
import
(
DOCTOR_PROCESS_STATUS
,
DOCTOR_TYPE
,
PHONE_HINTS
,
TOPIC_TYPE
,
TAG_TYPE
,
DisplayTag
,
SERVICE_FLAG
)
from
trans2es.models.query_word_conversion
import
TagConversion
class
WordRel
(
models
.
Model
):
class
Meta
:
app_label
=
'api'
db_table
=
'api_wordrel'
keyword
=
models
.
CharField
(
u'关键字'
,
max_length
=
50
)
category
=
models
.
CharField
(
u'分类'
,
max_length
=
5
,
choices
=
WORDREL_CATEGORY
)
created_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
,
auto_now_add
=
True
)
updated_time
=
models
.
DateTimeField
(
verbose_name
=
u'最后更新时间'
,
auto_now
=
True
)
class
WordRelResemble
(
models
.
Model
):
"""近义词数据表
"""
class
Meta
:
app_label
=
'api'
db_table
=
'api_wordrelresemble'
wordrel
=
models
.
ForeignKey
(
WordRel
,
related_name
=
'all_resembles'
)
word
=
models
.
CharField
(
u'近义词'
,
max_length
=
50
,
db_index
=
True
)
trans2es/type_info.py
View file @
3d6276c0
...
...
@@ -21,7 +21,10 @@ from trans2es.utils.collectwiki_transfer import CollectWikiTransfer
from
trans2es.utils.brandwiki_transfer
import
BrandWikiTransfer
from
trans2es.utils.productwiki_transfer
import
ProduceWikiTransfer
from
trans2es.utils.tag_transfer
import
TagTransfer
from
trans2es.utils.wordresemble
import
WordResemble
from
libs.es
import
ESPerform
from
libs.tools
import
tzlc
,
getMd5Digest
from
gm_types.gaia
import
SERVICE_ITEM_PRICE_TYPE
,
DOCTOR_TYPE
from
gm_types.gaia
import
(
DOCTOR_PROCESS_STATUS
,
DOCTOR_TYPE
,
PHONE_HINTS
,
TOPIC_TYPE
,
TAG_TYPE
,
DisplayTag
,
...
...
@@ -132,8 +135,9 @@ class TypeInfo(object):
))
continue
data
=
self
.
get_data_func
(
instance
)
(
item_dict
,
suggest_list
)
=
data
resemble_list
=
WordResemble
.
get_word_resemble_list
(
str
(
instance
.
name
))
(
item_dict
,
suggest_list
)
=
data
for
suggest_item
in
suggest_list
:
suggest_dict
=
copy
.
deepcopy
(
item_dict
)
suggest_dict
[
"suggest_type"
]
=
suggest_item
[
"suggest_type"
]
...
...
@@ -144,6 +148,14 @@ class TypeInfo(object):
"weight"
:
int
(
suggest_dict
[
"offline_score"
])
}
data_list
.
append
(
suggest_dict
)
for
resemble_item
in
resemble_list
:
resemble_dict
=
copy
.
deepcopy
(
suggest_dict
)
resemble_dict
[
"id"
]
=
suggest_dict
[
"id"
]
+
"_"
+
getMd5Digest
(
resemble_item
)
resemble_dict
[
"ori_name"
]
=
resemble_item
resemble_dict
[
"offline_score"
]
=
0
resemble_dict
[
"suggest"
][
"weight"
]
=
0
data_list
.
append
(
resemble_dict
)
except
Exception
:
traceback
.
print_exc
()
logging
.
exception
(
'bulk_get_data for name={}, doc_type={}, pk={}'
.
format
(
...
...
trans2es/utils/brandwiki_transfer.py
View file @
3d6276c0
...
...
@@ -10,7 +10,7 @@ from libs.cache import redis_client
import
json
from
trans2es.commons.commons
import
get_tips_suggest_list
from
trans2es.commons.words_utils
import
QueryWordAttr
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
class
BrandWikiTransfer
(
object
):
...
...
@@ -27,7 +27,7 @@ class BrandWikiTransfer(object):
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_project_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
"project"
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
name
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
3
...
...
trans2es/utils/collectwiki_transfer.py
View file @
3d6276c0
...
...
@@ -10,7 +10,7 @@ from libs.cache import redis_client
import
json
from
trans2es.commons.commons
import
get_tips_suggest_list
from
trans2es.commons.words_utils
import
QueryWordAttr
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
class
CollectWikiTransfer
(
object
):
...
...
@@ -27,7 +27,7 @@ class CollectWikiTransfer(object):
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_project_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
"project"
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
name
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
3
...
...
trans2es/utils/doctor_transfer.py
View file @
3d6276c0
...
...
@@ -12,7 +12,7 @@ from django.conf import settings
from
trans2es.commons.commons
import
get_tips_suggest_list
from
trans2es.commons.words_utils
import
QueryWordAttr
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
class
DoctorTransfer
(
object
):
...
...
@@ -86,7 +86,7 @@ class DoctorTransfer(object):
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_doctor_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
"doctor"
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
name
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
2
...
...
trans2es/utils/hospital_transfer.py
View file @
3d6276c0
...
...
@@ -10,7 +10,7 @@ from libs.cache import redis_client
import
json
from
trans2es.commons.commons
import
get_tips_suggest_list
from
trans2es.commons.words_utils
import
QueryWordAttr
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
class
HospitalTransfer
(
object
):
...
...
@@ -26,7 +26,7 @@ class HospitalTransfer(object):
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_hospital_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
"hospital"
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
name
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
1
...
...
trans2es/utils/itemwiki_transfer.py
View file @
3d6276c0
...
...
@@ -12,7 +12,7 @@ from django.conf import settings
from
trans2es.commons.commons
import
get_tips_suggest_list
from
trans2es.commons.words_utils
import
QueryWordAttr
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
class
ItemWikiTransfer
(
object
):
...
...
@@ -91,7 +91,7 @@ class ItemWikiTransfer(object):
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_project_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
"project"
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
name
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
3
...
...
trans2es/utils/productwiki_transfer.py
View file @
3d6276c0
...
...
@@ -10,7 +10,7 @@ from libs.cache import redis_client
import
json
from
trans2es.commons.commons
import
get_tips_suggest_list
from
trans2es.commons.words_utils
import
QueryWordAttr
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
class
ProduceWikiTransfer
(
object
):
...
...
@@ -27,7 +27,7 @@ class ProduceWikiTransfer(object):
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_project_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
"project"
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
name
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
3
...
...
trans2es/utils/tag_transfer.py
View file @
3d6276c0
...
...
@@ -11,7 +11,7 @@ import json
from
django.conf
import
settings
from
trans2es.commons.commons
import
get_tips_suggest_list
from
trans2es.commons.words_utils
import
QueryWordAttr
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
class
TagTransfer
(
object
):
...
...
@@ -98,7 +98,7 @@ class TagTransfer(object):
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_project_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
"project"
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
name
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
0
...
...
trans2es/utils/wordresemble.py
0 → 100644
View file @
3d6276c0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
os
import
sys
import
logging
import
traceback
from
libs.tools
import
tzlc
,
getMd5Digest
from
libs.es
import
ESPerform
from
libs.cache
import
redis_client
import
json
from
django.conf
import
settings
from
trans2es.models
import
wordresemble
class
WordResemble
(
object
):
@classmethod
def
get_word_resemble_list
(
cls
,
keyword
):
try
:
query_sql_item
=
wordresemble
.
WordRel
.
objects
.
filter
(
keyword
=
keyword
)
temp_list
=
list
()
for
sql_obj
in
query_sql_item
:
temp_list
.
extend
(
list
(
sql_obj
.
all_resembles
.
all
()
.
values_list
(
'word'
,
flat
=
True
)))
resemble_list
=
list
()
for
item
in
temp_list
:
resemble_list
.
extend
(
item
.
split
(
"、"
))
return
resemble_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
\ No newline at end of file
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