#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试优化后的 query_neo4j_graph 函数
"""

import sys
import os
import logging

# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(name)s - %(funcName)s - %(lineno)d - %(message)s'
)

def test_query_neo4j_graph():
    """测试优化后的 query_neo4j_graph 函数"""
    try:
        from app.core.data_parse.parse_system import query_neo4j_graph
        
        # 测试查询文本
        query_text = "大连硬石酒店"
        print(f"测试查询文本: {query_text}")
        print("-" * 50)
        
        # 调用函数
        result = query_neo4j_graph(query_text)
        
        # 打印结果
        print("函数执行结果:")
        print(f"状态码: {result.get('code')}")
        print(f"成功: {result.get('success')}")
        print(f"消息: {result.get('message')}")
        print(f"匹配的标签: {result.get('matched_labels')}")
        print(f"匹配的酒店: {result.get('matched_hotels')}")
        print(f"非空字段: {result.get('non_empty_fields')}")
        print(f"查询语句: {result.get('query')}")
        print(f"数据条数: {len(result.get('data', []))}")
        
        if result.get('data'):
            print("\n前5条数据:")
            for i, record in enumerate(result.get('data', [])[:5]):
                print(f"  {i+1}. {record}")
        
        return result
        
    except Exception as e:
        print(f"测试失败: {str(e)}")
        import traceback
        traceback.print_exc()
        return None

if __name__ == "__main__":
    print("开始测试优化后的 query_neo4j_graph 函数...")
    result = test_query_neo4j_graph()
    
    if result and result.get('success'):
        print("\n✅ 测试成功！函数工作正常。")
    else:
        print("\n❌ 测试失败！函数存在问题。") 