Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Handle restored file paths in find

jinzhenj8680a50ad19c
diff --git a/mineru/doclib/services/search_svc.py b/mineru/doclib/services/search_svc.py
index 57ae4b2b..cae9558d 100644
--- a/mineru/doclib/services/search_svc.py
+++ b/mineru/doclib/services/search_svc.py
@@ -118,9 +118,12 @@ class SearchService:
sql = (
f"SELECT f.*, d.title, d.page_count "
f"FROM files f LEFT JOIN docs d ON f.sha256 = d.sha256 "
- f"WHERE f.id IN ({placeholders}) AND f.status = ?"
+ f"WHERE f.id IN ({placeholders})"
)
- params = [*file_ids, FILE_STATUS_ACTIVE]
+ params = [*file_ids]
+ if refresh_file is None:
+ sql += " AND f.status = ?"
+ params.append(FILE_STATUS_ACTIVE)
if ext:
sql += " AND f.ext = ?"
params.append(ext.lower().lstrip("."))
@@ -164,7 +167,17 @@ class SearchService:
continue
if refreshed.file is not None and refreshed.file.status != FILE_STATUS_ACTIVE:
continue
- current_rows.append(file_row)
+ current_row = cast(
+ FilenameSearchFileRow | None,
+ await self.db.fetchone(
+ "SELECT f.*, d.title, d.page_count "
+ "FROM files f LEFT JOIN docs d ON f.sha256 = d.sha256 "
+ "WHERE f.id = ? AND f.status = ?",
+ (file_row["id"], FILE_STATUS_ACTIVE),
+ ),
+ )
+ if current_row is not None:
+ current_rows.append(current_row)
return current_rows
diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.py
index 4e675dc1..0beeebcd 100644
--- a/tests/unittest/test_doclib_cache_semantics.py
+++ b/tests/unittest/test_doclib_cache_semantics.py
@@ -1916,6 +1916,48 @@ def test_find_probes_and_filters_deleted_paths_without_rescan(tmp_path: Path) ->
asyncio.run(_run())
+def test_find_reactivates_restored_deleted_path_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 / "stale_restore.txt"
+ source.write_text("hello", encoding="utf-8")
+ assert await parse_svc.ensure_ingested(str(source)) is not None
+
+ source.unlink()
+ deleted = await server.find("stale_restore")
+ source.write_text("hello again", encoding="utf-8")
+ restored = await server.find("stale_restore")
+ row = await db.fetchone("SELECT status, deleted_at FROM files WHERE path=?", (str(source),))
+
+ assert deleted.total == 0
+ assert restored.total == 1
+ assert [result.filename for result in restored.results] == ["stale_restore.txt"]
+ assert row is not None
+ assert row["status"] == "active"
+ assert row["deleted_at"] is 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"))