Commit f3f39396 authored by lixiaofang's avatar lixiaofang

add

parent dbcfa8c3
...@@ -4,15 +4,14 @@ import os ...@@ -4,15 +4,14 @@ import os
import sys import sys
import logging import logging
import traceback import traceback
from libs.tools import tzlc,getMd5Digest from libs.tools import tzlc, getMd5Digest
from libs.es import ESPerform from libs.es import ESPerform
from libs.cache import redis_client from libs.cache import redis_client
import json import json
from django.conf import settings from django.conf import settings
from trans2es.commons.commons import get_tips_suggest_list from trans2es.commons.commons import get_tips_suggest_list
from trans2es.commons.words_utils import QueryWordAttr,get_tips_word_type from trans2es.commons.words_utils import QueryWordAttr, get_tips_word_type
class ItemWikiTransfer(object): class ItemWikiTransfer(object):
...@@ -44,12 +43,12 @@ class ItemWikiTransfer(object): ...@@ -44,12 +43,12 @@ class ItemWikiTransfer(object):
q = { q = {
"size": 0, "size": 0,
"query":{ "query": {
"bool":{ "bool": {
"should":[ "should": [
{"multi_match": multi_match} {"multi_match": multi_match}
], ],
"must":[ "must": [
{"term": {"is_online": True}} {"term": {"is_online": True}}
], ],
"minimum_should_match": 1 "minimum_should_match": 1
...@@ -57,14 +56,16 @@ class ItemWikiTransfer(object): ...@@ -57,14 +56,16 @@ class ItemWikiTransfer(object):
} }
} }
result_dict = ESPerform.get_search_results(ESPerform.get_cli(settings.GM_ORI_ES_INFO_LIST), sub_index_name="newwiki", doc_type="newwiki", query_body=q,offset=0,size=0) result_dict = ESPerform.get_search_results(ESPerform.get_cli(settings.GM_ORI_ES_INFO_LIST),
sub_index_name="newwiki", doc_type="newwiki", query_body=q,
offset=0, size=0)
doctor_results = result_dict["total_count"] doctor_results = result_dict["total_count"]
redis_key_prefix = "search_tips:tips_mapping_num" redis_key_prefix = "search_tips:tips_mapping_num"
redis_data = redis_client.hget(redis_key_prefix,wiki_name) redis_data = redis_client.hget(redis_key_prefix, wiki_name)
redis_val_dict = json.loads(str(redis_data,encoding="utf-8")) if redis_data else {} redis_val_dict = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
total_count = doctor_results total_count = doctor_results
if 'w' in redis_val_dict: if 'w' in redis_val_dict:
...@@ -73,12 +74,11 @@ class ItemWikiTransfer(object): ...@@ -73,12 +74,11 @@ class ItemWikiTransfer(object):
redis_val_dict['t'] = total_count redis_val_dict['t'] = total_count
redis_val_dict['w'] = doctor_results redis_val_dict['w'] = doctor_results
redis_client.hset(redis_key_prefix,wiki_name, json.dumps(redis_val_dict)) redis_client.hset(redis_key_prefix, wiki_name, json.dumps(redis_val_dict))
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
@classmethod @classmethod
def get_itemwiki_suggest_data_list(cls, instance): def get_itemwiki_suggest_data_list(cls, instance):
try: try:
...@@ -99,7 +99,7 @@ class ItemWikiTransfer(object): ...@@ -99,7 +99,7 @@ class ItemWikiTransfer(object):
suggest_list = get_tips_suggest_list(instance.name) suggest_list = get_tips_suggest_list(instance.name)
return (item_dict,suggest_list) return (item_dict, suggest_list)
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([],[]) return ([], [])
\ No newline at end of file
...@@ -4,24 +4,24 @@ import os ...@@ -4,24 +4,24 @@ import os
import sys import sys
import logging import logging
import traceback import traceback
from libs.tools import tzlc,getMd5Digest from libs.tools import tzlc, getMd5Digest
from libs.es import ESPerform from libs.es import ESPerform
from libs.cache import redis_client from libs.cache import redis_client
import json import json
from django.conf import settings from django.conf import settings
from trans2es.models import wordresemble from trans2es.models import wordresemble
class WordResemble(object): class WordResemble(object):
@classmethod @classmethod
def get_word_resemble_list(cls,keyword): def get_word_resemble_list(cls, keyword):
try: try:
query_sql_item = wordresemble.WordRel.objects.filter(keyword=keyword) query_sql_item = wordresemble.WordRel.objects.filter(keyword=keyword)
temp_list = list() temp_list = list()
for sql_obj in query_sql_item: for sql_obj in query_sql_item:
temp_list.extend(list(sql_obj.all_resembles.all().values_list('word',flat=True))) temp_list.extend(list(sql_obj.all_resembles.all().values_list('word', flat=True)))
resemble_list = list() resemble_list = list()
for item in temp_list: for item in temp_list:
...@@ -30,4 +30,4 @@ class WordResemble(object): ...@@ -30,4 +30,4 @@ class WordResemble(object):
return resemble_list return resemble_list
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list() return list()
\ No newline at end of file
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