Commit 957f5c0c authored by 段英荣's avatar 段英荣

Merge branch 'test' into 'master'

Test

See merge request !4
parents 79bb15a3 ca91e80d
FROM harbor.test.gengmei/base/gm-alpine:v1.3
COPY ./requirements.txt /tmp
RUN apk add --no-cache --virtual .build-deps \
bzip2-dev \
coreutils \
dpkg-dev dpkg \
expat-dev \
findutils \
gcc \
gdbm-dev \
libc-dev \
libffi-dev \
libnsl-dev \
libressl-dev \
libtirpc-dev \
linux-headers \
make \
ncurses-dev \
pax-utils \
readline-dev \
sqlite-dev \
tcl-dev \
tk \
tk-dev \
xz-dev \
zlib-dev \
# 业务相关依赖和安装工具
linux-headers \
python3-dev \
librdkafka-dev \
mariadb-client \
mariadb-dev \
git \
openssh \
\
&& apk add --no-cache jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
# 取消ssh第一次链接的确认
&& echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config \
&& apk add --no-cache mariadb-connector-c-dev libxml2-dev libxslt-dev librdkafka-dev \
&& pip install --no-cache-dir -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r /tmp/requirements.txt \
&& apk del .build-deps \
&& mkdir -p /data/log/search_tips/app
ENV GM_RPCD_DEPLOY_CONF_PATH "/srv/apps/search_tips/app_conf.xml" \
DJANGO_SETTINGS_MODULE=search_tips.settings
COPY . /srv/apps/search_tips/
WORKDIR /srv/apps/search_tips/
CMD gunicorn search_tips.wsgi:application -w 1 -k gevent -b 0.0.0.0:8000
......@@ -12,15 +12,17 @@ from libs.tools import g_hospital_pos_dict
from libs.tools import point_distance
def get_suggest_tips(query,lat,lng,offset=0,size=100):
def get_suggest_tips(query,lat,lng,offset=0,size=50):
try:
# ios输入法在某些情况下会携带\\u2006
query = query.replace("\u2006", '')
q = {
"suggest":{
"tips-suggest": {
"prefix": query,
"completion": {
"field": "suggest",
"size":size
"size": size
}
}
},
......@@ -47,7 +49,7 @@ def get_suggest_tips(query,lat,lng,offset=0,size=100):
else:
hit_item["_source"]["describe"] = "约" + str(distance) + "米"
else:
hit_item["_source"]["describe"] = "约" + str(1.0*distance/1000) + "km"
hit_item["_source"]["describe"] = "约" + str(round(1.0*distance/1000,1)) + "km"
else:
hit_item["_source"]["describe"] = ">1000km"
else:
......
......@@ -21,81 +21,98 @@ def uuid4():
def get_tips_suggest_list(instance_cn_name):
try:
ch_full_weight = 6.0 * 10000
py_full_weight = 3.0 * 10000
py_acronym_full_weight = 3.0 * 10000
ch_full_weight = 6.0 * 1000
py_full_weight = 3.0 * 1000
py_acronym_full_weight = 3.0 * 1000
py_acronym_prefix_weight = 2
ch_prefix_weight = 1.5
py_prefix_weight = 1.0
# 命中开始部分加权
begin_prefix_weight = 1.2 * 10000
begin_prefix_weight = 1.2 * 1000
ch_full_word = instance_cn_name.strip()
py_full_word = ''.join(lazy_pinyin(ch_full_word))
py_acronym_full_word = ''.join(lazy_pinyin(ch_full_word, style=pypinyin.FIRST_LETTER))
suggest_list = list()
suggest_dict = dict()
cur_index = 0
# 中文
for i in range(len(ch_full_word)):
for j in range(i, len(ch_full_word) + 1):
ch_name_term = ch_full_word[i:j].strip()
if ch_name_term:
prefix_weight = ch_prefix_weight if len(ch_name_term) != len(
ch_full_word) else ch_full_weight
suggest_type = 0 if len(ch_name_term) != len(ch_full_word) else 1
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
"input": [ch_name_term],
"word_weight": (1.0 * len(ch_name_term) / len(
(ch_full_word))) * prefix_weight * term_begin_prefix_weight,
"suggest_type": suggest_type,
"cur_index": cur_index
}
#for j in range(i, len(ch_full_word) + 1):
ch_name_term = ch_full_word[i:].strip()
if ch_name_term:
prefix_weight = ch_prefix_weight if len(ch_name_term) != len(ch_full_word) else ch_full_weight
suggest_type = 0 if len(ch_name_term) != len(ch_full_word) else 1
#term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
"input": [ch_name_term],
"word_weight": (1.0 * len(ch_name_term) / len((ch_full_word))) * prefix_weight,
"suggest_type": suggest_type,
}
if ch_name_term[0] not in suggest_dict:
cur_index += 1
suggest_list.append(suggest_item)
suggest_item["cur_index"] = cur_index
suggest_dict[ch_name_term[0]] = suggest_item
else:
suggest_dict[ch_name_term[0]]["input"].append(ch_name_term)
if suggest_item["word_weight"] > suggest_dict[ch_name_term[0]]["word_weight"]:
suggest_dict[ch_name_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[ch_name_term[0]]["suggest_type"] = suggest_item["suggest_type"]
# 拼音
for i in range(len(py_full_word)):
for j in range(i, len(py_full_word) + 1):
py_name_term = py_full_word[i:j].strip()
if py_full_word != ch_full_word:
for i in range(len(py_full_word)):
#for j in range(i, len(py_full_word) + 1):
py_name_term = py_full_word[i:].strip()
if py_name_term:
prefix_weight = py_prefix_weight if len(py_name_term) != len(
py_full_word) else py_full_weight
suggest_type = 2 if len(py_name_term) != len(py_full_word) else 3
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
#term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
"input": [py_name_term],
"word_weight": (1.0 * len(py_name_term) / len(
py_full_word)) * prefix_weight * term_begin_prefix_weight,
"suggest_type": suggest_type,
"cur_index": cur_index
"word_weight": (1.0 * len(py_name_term) / len(py_full_word)) * prefix_weight,
"suggest_type": suggest_type
}
cur_index += 1
suggest_list.append(suggest_item)
if py_name_term[0] not in suggest_dict:
cur_index += 1
suggest_item["cur_index"] = cur_index
suggest_dict[py_name_term[0]] = suggest_item
else:
suggest_dict[py_name_term[0]]["input"].append(py_name_term)
if suggest_item["word_weight"] > suggest_dict[py_name_term[0]]["word_weight"]:
suggest_dict[py_name_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[py_name_term[0]]["suggest_type"] = suggest_item["suggest_type"]
# 简写
for i in range(len(py_acronym_full_word)):
for j in range(i, len(py_acronym_full_word) + 1):
py_acronym_term = py_acronym_full_word[i:j].strip()
if py_acronym_full_word != py_full_word:
for i in range(len(py_acronym_full_word)):
#for j in range(i, len(py_acronym_full_word) + 1):
py_acronym_term = py_acronym_full_word[i:].strip()
if py_acronym_term:
prefix_weight = py_acronym_prefix_weight if len(py_acronym_term) != len(
py_acronym_full_word) else py_acronym_full_weight
suggest_type = 4 if len(py_acronym_term) != len(py_acronym_full_word) else 5
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
#term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
"input": [py_acronym_term],
"word_weight": (1.0 * len(py_acronym_term) / len(
py_acronym_full_word)) * prefix_weight * term_begin_prefix_weight,
"suggest_type": suggest_type,
"cur_index": cur_index
py_acronym_full_word)) * prefix_weight,
"suggest_type": suggest_type
}
cur_index += 1
suggest_list.append(suggest_item)
if py_acronym_term[0] not in suggest_dict:
cur_index += 1
suggest_item["cur_index"] = cur_index
suggest_dict[py_acronym_term[0]] = suggest_item
else:
suggest_dict[py_acronym_term[0]]["input"].append(py_acronym_term)
if suggest_item["word_weight"] > suggest_dict[py_acronym_term[0]]["word_weight"]:
suggest_dict[py_acronym_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[py_acronym_term[0]]["suggest_type"] = suggest_item["suggest_type"]
return suggest_list
return suggest_dict.values()
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list()
......
......@@ -133,6 +133,7 @@ class TypeInfo(object):
continue
data = self.get_data_func(instance)
(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"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment