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

modify search

parent 7be80ee9
...@@ -252,16 +252,16 @@ class TopicUtils(object): ...@@ -252,16 +252,16 @@ class TopicUtils(object):
] ]
if query is not None: # 搜索帖子 if query is not None: # 搜索帖子
multi_fields = { multi_fields = {
'description': 200, #'description': 200,
'content': 300, 'content': 300,
'name': 400, #'name': 400,
'tag_name_list': 300, 'tag_name_list': 300,
} }
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()] query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = { multi_match = {
'query': query, 'query': query,
'type': 'best_fields', 'type': 'best_fields',
'operator': 'and', 'operator': 'or',
'fields': query_fields, 'fields': query_fields,
} }
...@@ -299,30 +299,114 @@ class TopicUtils(object): ...@@ -299,30 +299,114 @@ class TopicUtils(object):
q["_source"] = { q["_source"] = {
"includes": ["id"] "includes": ["id"]
} }
q["sort"] = [
# { if query is None:
# "_script": { q["sort"] = [
# "type": "number", # {
# "script": { # "_script": {
# "lang": "expression", # "type": "number",
# "source": "_score+doc['offline_score']" # "script": {
# # "lang":"painless", # "lang": "expression",
# # "source":"_score+params._source.offline_score" # "source": "_score+doc['offline_score']"
# }, # # "lang":"painless",
# "order": "desc" # # "source":"_score+params._source.offline_score"
# } # },
# }, # "order": "desc"
{ # }
"offline_score": { # },
"order": "desc" {
} "offline_score": {
}, "order": "desc"
{ }
"_score": { },
"order": "desc" {
"_score": {
"order": "desc"
}
} }
]
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, result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name=index_type, query_body=q,
offset=offset, size=size, routing=routing) 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