Commit 5256d14e authored by 段英荣's avatar 段英荣

modify search

parent 7be80ee9
......@@ -252,16 +252,16 @@ class TopicUtils(object):
]
if query is not None: # 搜索帖子
multi_fields = {
'description': 200,
#'description': 200,
'content': 300,
'name': 400,
#'name': 400,
'tag_name_list': 300,
}
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = {
'query': query,
'type': 'best_fields',
'operator': 'and',
'operator': 'or',
'fields': query_fields,
}
......@@ -299,6 +299,8 @@ class TopicUtils(object):
q["_source"] = {
"includes": ["id"]
}
if query is None:
q["sort"] = [
# {
# "_script": {
......@@ -323,6 +325,88 @@ class TopicUtils(object):
}
}
]
else:
multi_match = {
'query': query,
'type': 'best_fields',
'operator': 'and',
'fields': ["content","tag_name_list"],
}
functions_list += [
{
"weight": 300,
"filter":{
"bool":{
"must":{
"term": {"content_level": 6},
},
"minimum_should_match": 1,
"should":[
{'multi_match': multi_match},
{"term": {"tag_list": tag_id}},
{"term": {"user_nick_name_pre": query.lower()}}
]
}
}
},
{
"weight": 200,
"filter": {
"bool": {
"must": {
"term": {"content_level": 5},
},
"minimum_should_match": 1,
"should": [
{'multi_match': multi_match},
{"term": {"tag_list": tag_id}},
{"term": {"user_nick_name_pre": query.lower()}}
]
}
}
},
{
"weight": 100,
"filter": {
"bool": {
"must": {
"term": {"content_level": 4},
},
"minimum_should_match": 1,
"should": [
{'multi_match': multi_match},
{"term": {"tag_list": tag_id}},
{"term": {"user_nick_name_pre": query.lower()}}
]
}
}
}
]
q["sort"] = [
# {
# "_script": {
# "type": "number",
# "script": {
# "lang": "expression",
# "source": "_score+doc['offline_score']"
# # "lang":"painless",
# # "source":"_score+params._source.offline_score"
# },
# "order": "desc"
# }
# },
{
"offline_score": {
"order": "desc"
}
},
{
"_score": {
"order": "desc"
}
}
]
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name=index_type, query_body=q,
offset=offset, size=size, routing=routing)
......
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