Commit 8e14a43a authored by 赵威's avatar 赵威

add merge list

parent 5d5b4817
import json import json
from itertools import chain, zip_longest
import redis import redis
from es_tool import es_query from es_tool import es_query
def merge_lists(*lol):
a = zip_longest(*lol)
return [i for i in chain(*a) if i is not None]
keywords = [ keywords = [
"瘦脸", "双眼皮", "补水", "美白嫩肤", "瘦小腿", "除皱", "隆鼻", "牙齿矫正", "脱毛", "祛斑", "控油", "面部祛脂", "隆胸", "垫鼻基底", "缩鼻翼", "生头发", "开眼角", "瘦肩", "祛痘", "瘦脸", "双眼皮", "补水", "美白嫩肤", "瘦小腿", "除皱", "隆鼻", "牙齿矫正", "脱毛", "祛斑", "控油", "面部祛脂", "隆胸", "垫鼻基底", "缩鼻翼", "生头发", "开眼角", "瘦肩", "祛痘",
"缩毛孔", "轮廓改善", "除眼底细纹", "眼部修复", "垫下巴", "颧骨内推", "除法令纹", "缩咬肌", "瘦臀部", "丰眼窝", "瘦手臂", "丰唇", "瘦腰腹", "瘦大腿", "填充泪沟", "洁面", "除面部细纹", "缩毛孔", "轮廓改善", "除眼底细纹", "眼部修复", "垫下巴", "颧骨内推", "除法令纹", "缩咬肌", "瘦臀部", "丰眼窝", "瘦手臂", "丰唇", "瘦腰腹", "瘦大腿", "填充泪沟", "洁面", "除面部细纹",
...@@ -124,15 +131,22 @@ def get_es_diary(keywords, city_tag_id=-1, version=False): ...@@ -124,15 +131,22 @@ def get_es_diary(keywords, city_tag_id=-1, version=False):
} }
q["sort"] = sort_list q["sort"] = sort_list
q["_source"] = {"includes": ["id", "second_demands"]} q["_source"] = {"includes": ["id", "second_demands"]}
es_res = es_query("diary", q, offset=0, size=500) es_res = es_query("diary", q, offset=0, size=5000)
diary_pairs = [] diary_dict = {}
for diary_info in es_res["hits"]["hits"]: for diary_info in es_res["hits"]["hits"]:
sd = ""
second_demands = diary_info["_source"].get("second_demands", []) second_demands = diary_info["_source"].get("second_demands", [])
if second_demands and len(second_demands) > 0: if second_demands and len(second_demands) > 0:
id = diary_info["_source"]["id"]
sd = second_demands[0] sd = second_demands[0]
diary_pairs.append((diary_info["_source"]["id"], sd)) if sd not in diary_dict:
return diary_pairs diary_dict[sd] = [id]
else:
diary_dict[sd].append(id)
res_pair = sorted(diary_dict.items(), key=lambda x: len(x[1]), reverse=True)
res_list = []
for _, v in res_pair:
res_list.append(v)
return merge_lists(res_list)
if __name__ == "__main__": if __name__ == "__main__":
......
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