|
|
|
|
@ -335,7 +335,11 @@ def add_limit_2query_body(limit_query: Union[List[dict], dict], body_key: str, q
|
|
|
|
|
})
|
|
|
|
|
# 遍历所有的组,满足条件则把limit添加进去
|
|
|
|
|
for group in query_body["QNode"]["QGroup"]:
|
|
|
|
|
# 相同的Key类型只能有一个,如果同类型有多个条件,需要追加到Items[]内,还不能重复
|
|
|
|
|
child_items = group["ChildItems"]
|
|
|
|
|
if group["Key"] == body_key:
|
|
|
|
|
if not child_items:
|
|
|
|
|
# 直接添加进去
|
|
|
|
|
if isinstance(limit_query, dict):
|
|
|
|
|
group["ChildItems"].append(limit_query)
|
|
|
|
|
elif isinstance(limit_query, list):
|
|
|
|
|
@ -343,6 +347,25 @@ def add_limit_2query_body(limit_query: Union[List[dict], dict], body_key: str, q
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError("不支持的limit类型 \n%s" % limit_query)
|
|
|
|
|
break
|
|
|
|
|
for child_item in child_items:
|
|
|
|
|
# 对child_item['Items']的值进行过滤,只添加不重复的
|
|
|
|
|
child_item_map = {}
|
|
|
|
|
[
|
|
|
|
|
child_item_map.setdefault(
|
|
|
|
|
i['Field'], {}
|
|
|
|
|
).update({
|
|
|
|
|
i['Key']: i['Value'] # 代表存在
|
|
|
|
|
})
|
|
|
|
|
for i in child_item['Items']
|
|
|
|
|
]
|
|
|
|
|
if child_item["Key"] == limit_query['Key']:
|
|
|
|
|
for limit_query_item in limit_query['Items']:
|
|
|
|
|
# 如果新的条件已存在,跳过
|
|
|
|
|
if child_item_map.get(limit_query_item['Field'], {}).get(limit_query_item["Key"]):
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
child_item['Items'].append(limit_query_item)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_retrieval(query: str):
|
|
|
|
|
@ -406,8 +429,8 @@ def add_search_word(search_content: str, base_query: dict = None):
|
|
|
|
|
|
|
|
|
|
def add_muti_group(
|
|
|
|
|
project: Union[SingleResultEnum, str],
|
|
|
|
|
value: str,
|
|
|
|
|
text_or_title: str,
|
|
|
|
|
value: Union[str, List[str]],
|
|
|
|
|
text_or_title: Union[str, List[str]],
|
|
|
|
|
base_query: dict = None,
|
|
|
|
|
**kwargs) -> dict:
|
|
|
|
|
"""
|
|
|
|
|
@ -424,22 +447,31 @@ def add_muti_group(
|
|
|
|
|
project = project.value
|
|
|
|
|
elif isinstance(project, str):
|
|
|
|
|
project = SingleResultEnum[project].value
|
|
|
|
|
# 判断value和text_or_title的类型是否一致,不一致抛出错误
|
|
|
|
|
if (isinstance(value, list) and not isinstance(text_or_title, list)) or (not isinstance(value, list) and isinstance(text_or_title, list)):
|
|
|
|
|
raise TypeError("参数类型不一致,必须都为list或str")
|
|
|
|
|
# 同一个分组多个条件,统统转成List
|
|
|
|
|
if isinstance(value, (str, int)):
|
|
|
|
|
value = [value]
|
|
|
|
|
if isinstance(text_or_title, (str, int)):
|
|
|
|
|
text_or_title = [text_or_title]
|
|
|
|
|
child_item = {
|
|
|
|
|
"Key": project,
|
|
|
|
|
"Title": "",
|
|
|
|
|
"Logic": 0,
|
|
|
|
|
"Items": [
|
|
|
|
|
{
|
|
|
|
|
"Key": value,
|
|
|
|
|
"Title": text_or_title,
|
|
|
|
|
"Key": val,
|
|
|
|
|
"Title": t1t,
|
|
|
|
|
"Logic": 1,
|
|
|
|
|
"Field": project,
|
|
|
|
|
"Operator": "DEFAULT",
|
|
|
|
|
"Value": value,
|
|
|
|
|
"Value": val,
|
|
|
|
|
"Value2": "",
|
|
|
|
|
"Name": project,
|
|
|
|
|
"ExtendType": 0
|
|
|
|
|
}],
|
|
|
|
|
} for val, t1t in zip(value, text_or_title)
|
|
|
|
|
],
|
|
|
|
|
"ChildItems": [
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|