Find registry entries matching ``identifier``. Match precedence (returns immediately on the first non-empty bucket): 1. Exact match on ``metadata['name']`` (the original filename). 2. Exact match on ``metadata['doc_name']`` (the slug). 3. Case-insensitive substring match on ei
(registry, identifier: str)
| 1188 | |
| 1189 | |
| 1190 | def _resolve_doc_identifier(registry, identifier: str) -> list[tuple[str, dict]]: |
| 1191 | """Find registry entries matching ``identifier``. |
| 1192 | |
| 1193 | Match precedence (returns immediately on the first non-empty bucket): |
| 1194 | 1. Exact match on ``metadata['name']`` (the original filename). |
| 1195 | 2. Exact match on ``metadata['doc_name']`` (the slug). |
| 1196 | 3. Case-insensitive substring match on either field. |
| 1197 | |
| 1198 | Returns ``[(file_hash, metadata), ...]``. Callers handle the empty, |
| 1199 | single, and multi-match cases. |
| 1200 | """ |
| 1201 | entries = registry.all_entries() |
| 1202 | |
| 1203 | exact_name = [(h, m) for h, m in entries.items() if m.get("name") == identifier] |
| 1204 | if exact_name: |
| 1205 | return exact_name |
| 1206 | |
| 1207 | exact_slug = [(h, m) for h, m in entries.items() if m.get("doc_name") == identifier] |
| 1208 | if exact_slug: |
| 1209 | return exact_slug |
| 1210 | |
| 1211 | needle = identifier.lower() |
| 1212 | fuzzy = [ |
| 1213 | (h, m) |
| 1214 | for h, m in entries.items() |
| 1215 | if needle in (m.get("name") or "").lower() or needle in (m.get("doc_name") or "").lower() |
| 1216 | ] |
| 1217 | return fuzzy |
| 1218 | |
| 1219 | |
| 1220 | @cli.command() |