|
|
|
@ -3,6 +3,8 @@ import os
|
|
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
|
import jieba
|
|
|
|
|
from elasticsearch import Elasticsearch
|
|
|
|
|
from gensim.models import KeyedVectors
|
|
|
|
|
from Config.Config import MS_MODEL_PATH, MS_MODEL_LIMIT
|
|
|
|
|
|
|
|
|
|
from ElasticSearch.Utils.ElasticsearchConnectionPool import ElasticsearchConnectionPool
|
|
|
|
|
|
|
|
|
@ -16,14 +18,13 @@ handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)
|
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
|
|
|
|
|
class EsSearchUtil:
|
|
|
|
|
|
|
|
|
|
def __init__(self, es_config):
|
|
|
|
|
"""
|
|
|
|
|
初始化Elasticsearch搜索工具
|
|
|
|
|
:param es_config: Elasticsearch配置字典,包含hosts, username, password, index_name等
|
|
|
|
|
"""
|
|
|
|
|
初始化Elasticsearch搜索工具
|
|
|
|
|
:param es_config: Elasticsearch配置字典,包含hosts, username, password, index_name等
|
|
|
|
|
"""
|
|
|
|
|
self.es_config = es_config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 初始化连接池
|
|
|
|
|
self.es_pool = ElasticsearchConnectionPool(
|
|
|
|
|
hosts=es_config['hosts'],
|
|
|
|
@ -31,7 +32,7 @@ class EsSearchUtil:
|
|
|
|
|
verify_certs=es_config.get('verify_certs', False),
|
|
|
|
|
max_connections=50
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 保留直接连接用于兼容
|
|
|
|
|
from elasticsearch import Elasticsearch
|
|
|
|
|
self.es = Elasticsearch(
|
|
|
|
@ -39,14 +40,14 @@ class EsSearchUtil:
|
|
|
|
|
basic_auth=es_config['basic_auth'],
|
|
|
|
|
verify_certs=es_config.get('verify_certs', False)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 确保es_conn属性存在以兼容旧代码
|
|
|
|
|
self.es_conn = self.es
|
|
|
|
|
|
|
|
|
|
def __init__(self, es_config):
|
|
|
|
|
from gensim.models import KeyedVectors
|
|
|
|
|
from Config.Config import MS_MODEL_PATH, MS_MODEL_LIMIT
|
|
|
|
|
|
|
|
|
|
# 确保es_conn属性存在以兼容旧代码
|
|
|
|
|
self.es_conn = self.es
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 加载预训练模型
|
|
|
|
|
self.model = KeyedVectors.load_word2vec_format(MS_MODEL_PATH, binary=False, limit=MS_MODEL_LIMIT)
|
|
|
|
|
logger.info(f"模型加载成功,词向量维度: {self.model.vector_size}")
|
|
|
|
|