This commit is contained in:
hsafaei
2025-07-23 11:12:24 +03:30
parent 8f63d947f3
commit 5d87fed26e
3 changed files with 132 additions and 3 deletions
+80
View File
@@ -110,6 +110,86 @@ def get_dict_qanon_title(file_path):
return dict
def searchQanonTitleOfContent(elastic, index_name, qanon_title, ts_data=""):
score = 100
body = {
"query": {
"bool": {
"must": [
{
"match": {
"title.keyword": {
"value": qanon_title
}
}
}
]
}
}
}
s_res = elastic.es.search(index=index_name, body=body)
total = s_res["hits"]["total"]['value']
if total == 1 :
item = s_res["hits"]["hits"][0]
return item["_id"], score, item
if total == 0 :
body = {
"query": {
"bool": {
"must": [
"more_like_this": {
"fields": [
"content.fa"
],
"like": qanon_title,
"min_term_freq": 1,
"max_query_terms": 12
}
}
]
}
}
s_res = elastic.es.search(index=index_name, body=body)
total = s_res["hits"]["total"]['value']
qanon_title_sample = re.sub(r"( |\u200C)+", "", qanon_title)
list_equal = []
for item in s_res["hits"]["hits"]:
title = item['_source']['title']
# حذف اسپیسها
title_sample = re.sub(r"( |\u200C)+", "", title)
if title_sample == qanon_title_sample :
list_equal.append(item)
else :
qanon_title_sample = get_qanon_title_sample(qanon_title)
title_sample = get_qanon_title_sample(title)
if title_sample == qanon_title_sample :
list_equal.append(item)
if len(list_equal) == 1 :
item = list_equal[0]
score = 90
if ts_data == item['_source']['ts_date'] :
score = 100
return item["_id"], score, item
for item in list_equal :
if ts_data == item['_source']['ts_date'] :
score = 100
return item["_id"], score, item
if len(list_equal) :
score = 90
item = list_equal[0]
return item["_id"], score, item
return 0, 0, {}
def searchQanonId(elastic, index_name, qanon_title, ts_data=""):
score = 100
body = {