// tests/live_search_test.rs use astroresearch::Config; use astroresearch::clients::ads::AdsClient; use astroresearch::clients::arxiv::ArxivClient; #[tokio::test] async fn test_live_search_comparisons() -> anyhow::Result<()> { // 载入配置以获取 ADS_API_KEY let config = Config::from_env(); if config.ads_api_key.is_empty() { println!("警告: 未在环境配置中检测到 ADS_API_KEY,跳过 ADS 集成测试。"); } let ads = AdsClient::new(config.ads_api_key.clone()); let arxiv = ArxivClient::new(); println!("================= 开始真实检索逻辑集成测试 ================="); // ---------------------------------------- // 测试 1: 比较 "OR" 与 "AND" 逻辑的数据量差异 // ---------------------------------------- let query_or = "\"hot subdwarf\" OR Gaia"; let query_and = "\"hot subdwarf\" AND Gaia"; if !config.ads_api_key.is_empty() { let count_ads_or = ads.get_total_count(query_or).await?; let count_ads_and = ads.get_total_count(query_and).await?; println!("NASA ADS 平台:"); println!(" - (OR) \"{}\" 匹配数: {} 篇", query_or, count_ads_or); println!(" - (AND) \"{}\" 匹配数: {} 篇", query_and, count_ads_and); assert!(count_ads_or > count_ads_and, "错误: OR 结果应该多于 AND"); } let count_arxiv_or = arxiv.get_total_count(query_or).await?; let count_arxiv_and = arxiv.get_total_count(query_and).await?; println!("arXiv 平台:"); println!(" - (OR) \"{}\" 匹配数: {} 篇", query_or, count_arxiv_or); println!(" - (AND) \"{}\" 匹配数: {} 篇", query_and, count_arxiv_and); assert!(count_arxiv_or > count_arxiv_and, "错误: arXiv 的 OR 结果应该多于 AND"); // ---------------------------------------- // 测试 2: 比较基础词组与含有 "NOT" 排除条件的数据量差异 // ---------------------------------------- let query_base = "\"hot subdwarf\""; let query_not = "\"hot subdwarf\" NOT \"white dwarf\""; if !config.ads_api_key.is_empty() { let count_ads_base = ads.get_total_count(query_base).await?; let count_ads_not = ads.get_total_count(query_not).await?; println!("NASA ADS 平台:"); println!(" - (基础) \"{}\" 匹配数: {} 篇", query_base, count_ads_base); println!(" - (排除) \"{}\" 匹配数: {} 篇", query_not, count_ads_not); assert!(count_ads_base >= count_ads_not, "错误: 基础结果应该大于或等于排除后的结果"); } let count_arxiv_base = arxiv.get_total_count(query_base).await?; let count_arxiv_not = arxiv.get_total_count(query_not).await?; println!("arXiv 平台:"); println!(" - (基础) \"{}\" 匹配数: {} 篇", query_base, count_arxiv_base); println!(" - (排除) \"{}\" 匹配数: {} 篇", query_not, count_arxiv_not); assert!(count_arxiv_base >= count_arxiv_not, "错误: arXiv 基础结果应该大于或等于排除后的结果"); println!("================= 真实检索逻辑集成测试全部通过 ================="); Ok(()) }