From 9d397a9db40774439a6fcdcf992d3f109ceccc74 Mon Sep 17 00:00:00 2001 From: Chia-Hsuan Hsu Date: Mon, 4 May 2026 20:31:40 +0800 Subject: [PATCH] filter figure captions and URLs from heading detection Add filtering in is_heading_candidate() to prevent false positives: - Figure/Table captions (e.g. "Figure 1: Results") - URLs (http/https/www) - Email addresses --- crates/open-core/src/pdf.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/open-core/src/pdf.rs b/crates/open-core/src/pdf.rs index a8a98f7..81d0b06 100644 --- a/crates/open-core/src/pdf.rs +++ b/crates/open-core/src/pdf.rs @@ -644,6 +644,23 @@ fn is_heading_candidate(text: &str, is_first: bool) -> bool { return false; } + let lower = trimmed.to_lowercase(); + + if lower.starts_with("figure ") || lower.starts_with("fig.") || lower.starts_with("table ") { + return false; + } + + if trimmed.starts_with("http://") + || trimmed.starts_with("https://") + || trimmed.starts_with("www.") + { + return false; + } + + if trimmed.contains('@') && !trimmed.contains(' ') { + return false; + } + let len = trimmed.len(); if is_first && len >= 3 {