Skip to content

scene

场景相关 CLI 命令(全文检索)。

场景全文检索(需 Dimine 运行)。

Source code in dimine_python_sdk\cli\commands\scene.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def cmd_scene_search(
    fmt: str,
    keyword: str,
    scope: str | None,
    files: str | None,
    case_sensitive: bool,
) -> None:
    """场景全文检索(需 Dimine 运行)。"""
    err = require_remote_sdk()
    if err:
        output_error(err, fmt)

    try:
        scopes = _parse_scope(scope) if scope else None
        file_list = _parse_files(files) if files else None
        if not keyword:
            raise ValueError("--keyword 检索正则表达式不能为空")
    except ValueError as e:
        output_error(str(e), fmt)

    async def _run():
        client = await get_client()
        result = await client.search_scene(
            keyword,
            scope=scopes,
            files=file_list,
            case_sensitive=case_sensitive,
        )
        counts: dict = {}
        for hit in result.results:
            counts[hit.type] = counts.get(hit.type, 0) + 1
        return {
            "success": True,
            "keyword": keyword,
            "total_count": result.total_count,
            "counts": counts,
            "results": [hit.model_dump(exclude_none=True) for hit in result.results],
        }

    try:
        result = run_cli_async(_run())
        output_result(result, fmt)
    except Exception as e:
        handle_sdk_error(e, fmt, "场景全文检索失败")

register_commands(subparsers, format_parent)

向 subparsers 注册场景相关子命令。

Source code in dimine_python_sdk\cli\commands\scene.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def register_commands(subparsers, format_parent) -> None:
    """向 subparsers 注册场景相关子命令。"""
    p = subparsers.add_parser(
        "scene-search",
        parents=[format_parent],
        help="场景全文检索(按正则检索文件/图层/要素/实体,文字标注归入实体)",
    )
    p.add_argument("--keyword", required=True, help="检索正则表达式,如 '^(BH|ZK)-\\d+$' 或 '.*cu.*'")
    p.add_argument("--scope", default=None, help="检索范围,逗号分隔,可选: file,layer,feature,entity(默认全部)")
    p.add_argument("--files", default=None, help="限定检索的文件,逗号分隔的文件id或文件名(默认当前场景所有文件)")
    p.add_argument("--case-sensitive", action="store_true", help="区分大小写(默认不区分)")