Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
Probe find results for stale paths
jinzhenj540417e9e50d
diff --git a/mineru/doclib/server.py b/mineru/doclib/server.pyindex 1f3fd2bd..21ecc482 100644--- a/mineru/doclib/server.py+++ b/mineru/doclib/server.py@@ -755,7 +755,12 @@ class DoclibServer(AsyncDoclibInterface):start_ms = _now_ms()await _record_telemetry_count(self.state, "find.request.count")try:- results, total = await self.state.search_svc.search_filenames(query=query, ext=ext, limit=limit)+ results, total = await self.state.search_svc.search_filenames(+ query=query,+ ext=ext,+ limit=limit,+ refresh_file=self.state.parse_svc.refresh_file,+ )response = FindResponse(results=[_find_result(row) for row in results], total=total, query=query)dims = {"status": "succeeded"}await _record_telemetry_count(self.state, "find.finished.count", dimensions=dims)diff --git a/mineru/doclib/services/search_svc.py b/mineru/doclib/services/search_svc.pyindex 998868ba..57ae4b2b 100644--- a/mineru/doclib/services/search_svc.py+++ b/mineru/doclib/services/search_svc.py@@ -2,7 +2,8 @@from __future__ import annotations-from typing import cast+from collections.abc import Awaitable, Callable+from typing import TYPE_CHECKING, castfrom ...types import TIER_ORDER, Tierfrom ..core.db import DatabaseManager@@ -10,6 +11,11 @@ from ..core.fts import FTSManager, strip_sepfrom ..rows import ContentSearchResultRow, FilenameSearchFileRow, FilenameSearchResultRow, SearchFileRowfrom ..types import FILE_STATUS_ACTIVE+if TYPE_CHECKING:+ from .parse_svc import FileRefreshResult++FilenamePathProbe = Callable[[str], Awaitable["FileRefreshResult"]]+class SearchService:def __init__(self, db: DatabaseManager, fts: FTSManager) -> None:@@ -100,7 +106,7 @@ class SearchService:# ── filename search ─────────────────────────────────────────async def search_filenames(- self, query: str, ext: str | None = None, limit: int = 50+ self, query: str, ext: str | None = None, limit: int = 50, *, refresh_file: FilenamePathProbe | None = None) -> tuple[list[FilenameSearchResultRow], int]:"""Search filenames only. Returns (results, total_count)."""rows = await self.fts.search_filenames(query, limit=limit)@@ -119,6 +125,8 @@ class SearchService:sql += " AND f.ext = ?"params.append(ext.lower().lstrip("."))file_rows = cast(list[FilenameSearchFileRow], await self.db.fetchall(sql, tuple(params)))+ if refresh_file is not None:+ file_rows = await self._filter_probe_stale_filename_rows(file_rows, refresh_file)files_by_id = {fr["id"]: fr for fr in file_rows}@@ -144,6 +152,21 @@ class SearchService:total = len(results)return results, total+ async def _filter_probe_stale_filename_rows(+ self,+ file_rows: list[FilenameSearchFileRow],+ refresh_file: FilenamePathProbe,+ ) -> list[FilenameSearchFileRow]:+ current_rows: list[FilenameSearchFileRow] = []+ for file_row in file_rows:+ refreshed = await refresh_file(file_row["path"])+ if refreshed.status in {"missing", "deleted", "unreachable"}:+ continue+ if refreshed.file is not None and refreshed.file.status != FILE_STATUS_ACTIVE:+ continue+ current_rows.append(file_row)+ return current_rows+def _matches_tier(value: object, *, tier: Tier | None, min_tier: Tier | None) -> bool:if not isinstance(value, str) or value not in TIER_ORDER:diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.pyindex e0eb8a80..9ec8eed5 100644--- a/tests/unittest/test_doclib_cache_semantics.py+++ b/tests/unittest/test_doclib_cache_semantics.py@@ -1567,6 +1567,45 @@ def test_find_filters_by_ext(tmp_path: Path) -> None:asyncio.run(_run())+def test_find_probes_and_filters_deleted_paths_without_rescan(tmp_path: Path) -> None:+ async def _run() -> None:+ db = DatabaseManager(str(tmp_path / "doclib.db"))+ await db.initialize()+ fts = FTSManager(db)+ config_svc = ConfigService(db)+ parse_svc = ParseService(+ db=db,+ fts=fts,+ config_svc=config_svc,+ data_dir=str(tmp_path / "data"),+ parse_lock_timeout_sec=1800,+ )+ server = DoclibServer(+ SimpleNamespace(+ db=db,+ fts=fts,+ parse_svc=parse_svc,+ search_svc=SearchService(db, fts),+ telemetry_svc=None,+ )+ )+ source = tmp_path / "bench1.txt"+ source.write_text("hello", encoding="utf-8")+ assert await parse_svc.ensure_ingested(str(source)) is not None++ source.unlink()+ result = await server.find("bench1")+ row = await db.fetchone("SELECT status, deleted_at FROM files WHERE path=?", (str(source),))++ assert result.total == 0+ assert result.results == []+ assert row is not None+ assert row["status"] == "deleted"+ assert row["deleted_at"] is not None++ asyncio.run(_run())++def test_refresh_file_marks_only_current_file_unreachable_when_watch_root_is_missing(tmp_path: Path) -> None:async def _run() -> None:db = DatabaseManager(str(tmp_path / "doclib.db"))