Filter ranked search by public source and excluded text before pagination

This commit is contained in:
2026-12-03 03:20:18 +08:00
parent c0b5455582
commit 20d3d3fc62
7 changed files with 113 additions and 8 deletions
+28
View File
@@ -183,3 +183,31 @@ fn measure_ranked_queries_over_25000_posts() {
);
}
}
#[test]
fn source_and_exclusions_apply_before_total_and_offset() {
let mut index = MemoryIndex::default();
for (chat, message, title, body) in [
(1, 1, "相机 广告", ""),
(1, 2, "相机", "转发"),
(1, 3, "相机", ""),
(1, 4, "相机", ""),
(2, 1, "相机", ""),
] {
index.upsert(post(chat, message, title, body)).unwrap();
}
let mut query = Query::new("exclude:广告 from:@CHAT1 exclude:转发 相机");
query.offset = 1;
query.limit = 1;
let page = index.search(&query).unwrap();
assert_eq!(page.total, 2);
assert_eq!(page.hits[0].url(), "https://t.me/chat1/4");
for invalid in [
"from:@x/y 相机",
"from:chat1 from:chat2 相机",
"exclude: 相机",
"from:chat1",
] {
assert_eq!(index.search(&Query::new(invalid)).unwrap().total, 0);
}
}