|
|
|
@ -1,31 +1,12 @@
|
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
|
|
|
|
|
|
from Config.Config import ES_CONFIG
|
|
|
|
|
from ElasticSearch.Utils.ElasticsearchConnectionPool import ElasticsearchConnectionPool
|
|
|
|
|
|
|
|
|
|
# 初始化日志
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
# 确保日志目录存在
|
|
|
|
|
os.makedirs('Logs', exist_ok=True)
|
|
|
|
|
handler = RotatingFileHandler('Logs/start.log', maxBytes=1024 * 1024, backupCount=5)
|
|
|
|
|
handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_es_pool():
|
|
|
|
|
# 初始化Elasticsearch连接池
|
|
|
|
|
es_pool = ElasticsearchConnectionPool(
|
|
|
|
|
hosts=ES_CONFIG["hosts"],
|
|
|
|
|
basic_auth=ES_CONFIG["basic_auth"],
|
|
|
|
|
verify_certs=ES_CONFIG["verify_certs"],
|
|
|
|
|
max_connections=50
|
|
|
|
|
)
|
|
|
|
|
logger.info("Elasticsearch连接池初始化完成")
|
|
|
|
|
return es_pool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 导入EsSearchUtil
|
|
|
|
|
from Util.EsSearchUtil import EsSearchUtil
|
|
|
|
@ -35,9 +16,6 @@ es_search_util = EsSearchUtil(ES_CONFIG)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
# 初始化ES连接池
|
|
|
|
|
es_pool = init_es_pool()
|
|
|
|
|
|
|
|
|
|
# 测试查询
|
|
|
|
|
query = "小学数学中有哪些模型"
|
|
|
|
|
query_tags = ["MATH_1"] # 默认搜索标签,可修改
|
|
|
|
@ -45,7 +23,7 @@ def main():
|
|
|
|
|
print(f"原始查询文本: {query}")
|
|
|
|
|
|
|
|
|
|
# 执行混合搜索
|
|
|
|
|
es_conn = es_pool.get_connection()
|
|
|
|
|
es_conn = es_search_util.es_pool.get_connection()
|
|
|
|
|
try:
|
|
|
|
|
# 向量搜索
|
|
|
|
|
print("\n=== 向量搜索阶段 ===")
|
|
|
|
@ -125,10 +103,7 @@ def main():
|
|
|
|
|
# print(f" 详细: {hit['_source']['tags']['full_content']}")
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
es_pool.release_connection(es_conn)
|
|
|
|
|
|
|
|
|
|
# 关闭连接池
|
|
|
|
|
es_pool.close()
|
|
|
|
|
es_search_util.es_pool.release_connection(es_conn)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|
|
|
|
|