Commit 3db822c1 authored by 张彦钊's avatar 张彦钊

add

parent a66215bd
...@@ -56,7 +56,7 @@ def es_query(doc, body, offset, size, es=None): ...@@ -56,7 +56,7 @@ def es_query(doc, body, offset, size, es=None):
from_=offset, from_=offset,
size=size) size=size)
number = res["hits"]["total"] or 0 number = res["hits"]["total"]
return number return number
...@@ -424,13 +424,13 @@ def answer(): ...@@ -424,13 +424,13 @@ def answer():
tmp.append(es_query('answer', video_star5_q, 0, 1)) tmp.append(es_query('answer', video_star5_q, 0, 1))
total_list.append(tmp) total_list.append(tmp)
print(i) # print(i)
print(tmp) # print(tmp)
df = pd.DataFrame(total_list) df = pd.DataFrame(total_list)
df = df.rename(columns={0: "tag", 1: "star_3", 2: "star_4", 3: "star_5", df = df.rename(columns={0: "tag", 1: "star_3", 2: "star_4", 3: "star_5",
4: "video_star_3", 5: "video_star_4", 6: "video_star_5"}) 4: "video_star_3", 5: "video_star_4", 6: "video_star_5"})
df.to_csv("/home/gmuser/answer.csv", index=False) df.to_csv("/home/gmuser/answer.csv", index=False, encoding="utf_8_sig")
def question(): def question():
...@@ -617,14 +617,13 @@ def question(): ...@@ -617,14 +617,13 @@ def question():
for i in tags: for i in tags:
tmp = [i] tmp = [i]
query = i query = i
# TODO 下面两个q语句
q = { q = {
"query": {"filtered": { "query": {"filtered": {
"filter": { "filter": {
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["title^1", "content^1", "tags^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -649,7 +648,7 @@ def question(): ...@@ -649,7 +648,7 @@ def question():
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["title^1", "content^1", "tags^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -672,12 +671,12 @@ def question(): ...@@ -672,12 +671,12 @@ def question():
tmp.append(es_query(category, video_q, 0, 1)) tmp.append(es_query(category, video_q, 0, 1))
total_list.append(tmp) total_list.append(tmp)
print(i) # print(i)
print(tmp) # print(tmp)
df = pd.DataFrame(total_list) df = pd.DataFrame(total_list)
df = df.rename(columns={0: "tag", 1: "number", 2: "video_number"}) df = df.rename(columns={0: "tag", 1: "number", 2: "video_number"})
df.to_csv("/home/gmuser/question.csv", index=False) df.to_csv("/home/gmuser/question.csv", index=False, encoding="utf_8_sig")
def topic(): def topic():
...@@ -871,7 +870,8 @@ def topic(): ...@@ -871,7 +870,8 @@ def topic():
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["content^1", "author^1", "tractate_tag_name^1",
"tractate_tag_name_content^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -883,6 +883,11 @@ def topic(): ...@@ -883,6 +883,11 @@ def topic():
}, {"term": { }, {"term": {
"content_level": 3 "content_level": 3
} }
},
{
"term": {
"status": "3"
}
}] }]
} }
...@@ -893,13 +898,13 @@ def topic(): ...@@ -893,13 +898,13 @@ def topic():
tmp.append(es_query(category, star3_q, 0, 1)) tmp.append(es_query(category, star3_q, 0, 1))
star4_q = { star4_q = {
"query": { "query": {"filtered": {
"filtered": {
"filter": { "filter": {
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["content^1", "author^1", "tractate_tag_name^1",
"tractate_tag_name_content^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -911,6 +916,11 @@ def topic(): ...@@ -911,6 +916,11 @@ def topic():
}, {"term": { }, {"term": {
"content_level": 4 "content_level": 4
} }
},
{
"term": {
"status": "3"
}
}] }]
} }
...@@ -921,13 +931,13 @@ def topic(): ...@@ -921,13 +931,13 @@ def topic():
tmp.append(es_query(category, star4_q, 0, 1)) tmp.append(es_query(category, star4_q, 0, 1))
star5_q = { star5_q = {
"query": { "query": {"filtered": {
"filtered": {
"filter": { "filter": {
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["content^1", "author^1", "tractate_tag_name^1",
"tractate_tag_name_content^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -939,6 +949,11 @@ def topic(): ...@@ -939,6 +949,11 @@ def topic():
}, {"term": { }, {"term": {
"content_level": 5 "content_level": 5
} }
},
{
"term": {
"status": "3"
}
}] }]
} }
...@@ -949,13 +964,13 @@ def topic(): ...@@ -949,13 +964,13 @@ def topic():
tmp.append(es_query(category, star5_q, 0, 1)) tmp.append(es_query(category, star5_q, 0, 1))
video_star3_q = { video_star3_q = {
"query": { "query": {"filtered": {
"filtered": {
"filter": { "filter": {
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["content^1", "author^1", "tractate_tag_name^1",
"tractate_tag_name_content^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -964,14 +979,15 @@ def topic(): ...@@ -964,14 +979,15 @@ def topic():
"term": { "term": {
"is_online": True "is_online": True
} }
}, {
"term": {
"is_video": True
}
}, {"term": { }, {"term": {
"content_level": 3 "content_level": 3
} }
}] },
{
"term": {
"status": "3"
}
}, {"term": {"is_video": True}}]
} }
} }
...@@ -981,13 +997,13 @@ def topic(): ...@@ -981,13 +997,13 @@ def topic():
tmp.append(es_query(category, video_star3_q, 0, 1)) tmp.append(es_query(category, video_star3_q, 0, 1))
video_star4_q = { video_star4_q = {
"query": { "query": {"filtered": {
"filtered": {
"filter": { "filter": {
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["content^1", "author^1", "tractate_tag_name^1",
"tractate_tag_name_content^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -996,14 +1012,15 @@ def topic(): ...@@ -996,14 +1012,15 @@ def topic():
"term": { "term": {
"is_online": True "is_online": True
} }
}, {
"term": {
"is_video": True
}
}, {"term": { }, {"term": {
"content_level": 4 "content_level": 4
} }
}] },
{
"term": {
"status": "3"
}
}, {"term": {"is_video": True}}]
} }
} }
...@@ -1013,13 +1030,13 @@ def topic(): ...@@ -1013,13 +1030,13 @@ def topic():
tmp.append(es_query(category, video_star4_q, 0, 1)) tmp.append(es_query(category, video_star4_q, 0, 1))
video_star5_q = { video_star5_q = {
"query": { "query": {"filtered": {
"filtered": {
"filter": { "filter": {
"bool": { "bool": {
"must": [{ "must": [{
"multi_match": { "multi_match": {
"fields": ["title^1", "desc^1", "answer^1"], "fields": ["content^1", "author^1", "tractate_tag_name^1",
"tractate_tag_name_content^1"],
"operator": query_operator, "operator": query_operator,
"type": query_type, "type": query_type,
"query": query "query": query
...@@ -1028,14 +1045,15 @@ def topic(): ...@@ -1028,14 +1045,15 @@ def topic():
"term": { "term": {
"is_online": True "is_online": True
} }
}, {
"term": {
"is_video": True
}
}, {"term": { }, {"term": {
"content_level": 5 "content_level": 5
} }
}] },
{
"term": {
"status": "3"
}
}, {"term": {"is_video": True}}]
} }
} }
...@@ -1045,16 +1063,20 @@ def topic(): ...@@ -1045,16 +1063,20 @@ def topic():
tmp.append(es_query(category, video_star5_q, 0, 1)) tmp.append(es_query(category, video_star5_q, 0, 1))
total_list.append(tmp) total_list.append(tmp)
print(i) # print(i)
print(tmp) # print(tmp)
df = pd.DataFrame(total_list) df = pd.DataFrame(total_list)
df = df.rename(columns={0: "tag", 1: "star_3", 2: "star_4", 3: "star_5", df = df.rename(columns={0: "tag", 1: "star_3", 2: "star_4", 3: "star_5",
4: "video_star_3", 5: "video_star_4", 6: "video_star_5"}) 4: "video_star_3", 5: "video_star_4", 6: "video_star_5"})
df.to_csv("/home/gmuser/topic.csv", index=False) df.to_csv("/home/gmuser/topic.csv", index=False, encoding="utf_8_sig")
if __name__ == "__main__": if __name__ == "__main__":
answer() answer()
topic()
print("topic")
question()
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