Write an enriched document to storage, updating the index with keywords.
(doc: dict)
| 47 | |
| 48 | |
| 49 | def save_processed(doc: dict) -> str: |
| 50 | """Write an enriched document to storage, updating the index with keywords.""" |
| 51 | _ensure_storage() |
| 52 | record_id = doc.get("id") or str(uuid.uuid4())[:8] |
| 53 | path = STORAGE_DIR / f"{record_id}_processed.json" |
| 54 | path.write_text(json.dumps(doc, indent=2)) |
| 55 | |
| 56 | index = load_index() |
| 57 | if record_id not in index: |
| 58 | index[record_id] = {} |
| 59 | index[record_id]["keywords"] = doc.get("keywords", []) |
| 60 | index[record_id]["cross_refs"] = [r["id"] for r in doc.get("cross_refs", [])] |
| 61 | save_index(index) |
| 62 | return record_id |
| 63 | |
| 64 | |
| 65 | def load_record(record_id: str) -> dict: |
no test coverage detected