- src/ 按 clients/services/api 分层,Config 提升至 crate 根 - 新增 batch_sync.rs(双源并行收割)、query_parser.rs(多平台检索式转换) - build.rs 自动触发前端 npm install & build - SearchPanel 支持分页/排序/每页条数/高级检索构建器,前端加入搜索缓存 - 新增 SyncPanel 替换 SettingsPanel;新增 live_search 集成测试
66 lines
3.1 KiB
Rust
66 lines
3.1 KiB
Rust
// 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(())
|
||
}
|