Entry point for the source-search subcommand. *db_path* must be a resolved path to an existing index. *repo* is a canonical repo id (the ``id`` field from the ``repos`` command output); pass ``None`` to search across all indexed repos. *node_types* optionally restricts results to sp
(
query: str,
db_path: str | None,
*,
repo: str | None = None,
node_types: list[str] | None = None,
limit: int = 20,
output_json: bool = False,
)
| 176 | |
| 177 | |
| 178 | def run_source_search( |
| 179 | query: str, |
| 180 | db_path: str | None, |
| 181 | *, |
| 182 | repo: str | None = None, |
| 183 | node_types: list[str] | None = None, |
| 184 | limit: int = 20, |
| 185 | output_json: bool = False, |
| 186 | ) -> None: |
| 187 | """Entry point for the source-search subcommand. |
| 188 | |
| 189 | *db_path* must be a resolved path to an existing index. *repo* is |
| 190 | a canonical repo id (the ``id`` field from the ``repos`` command |
| 191 | output); pass ``None`` to search across all indexed repos. |
| 192 | *node_types* optionally restricts results to specific node types |
| 193 | (``Function``, ``Class``, ...). *output_json* emits a structured |
| 194 | object instead of formatted text. |
| 195 | """ |
| 196 | from opentrace_agent.store import GraphStore |
| 197 | |
| 198 | store = GraphStore(db_path, read_only=True) |
| 199 | try: |
| 200 | resolved_repo = _resolve_repo(store, repo) |
| 201 | # Over-fetch one row beyond `limit` so we can distinguish |
| 202 | # "exactly `limit` matches in the graph" from "more existed, |
| 203 | # truncated here". The +1 row is then trimmed before output. |
| 204 | results = _run_fts_search(store, query, resolved_repo, node_types, limit + 1) |
| 205 | truncated = len(results) > limit |
| 206 | if truncated: |
| 207 | results = results[:limit] |
| 208 | |
| 209 | repo_ids = [resolved_repo] if resolved_repo else _load_repo_ids(store) |
| 210 | |
| 211 | if output_json: |
| 212 | _emit_json(query, resolved_repo, results, truncated, limit) |
| 213 | else: |
| 214 | _emit_text(query, resolved_repo, results, repo_ids) |
| 215 | finally: |
| 216 | store.close() |
| 217 | |
| 218 | |
| 219 | def _emit_json( |
no test coverage detected