Skip to content

CLI Search Resource

CLISearchResource(cli)

Bases: BaseCLIResource

CLI resource for vault search operations.

Attributes:

Name Type Description
_cli

Reference to the parent ObsidianCLI instance.

Source code in src/aiobsidian/cli/_base.py
def __init__(self, cli: ObsidianCLI) -> None:
    self._cli = cli

open(query) async

Open the search panel in the Obsidian UI with a query.

Parameters:

Name Type Description Default
query str

Search query string.

required
Source code in src/aiobsidian/cli/search.py
async def open(self, query: str) -> None:
    """Open the search panel in the Obsidian UI with a query.

    Args:
        query: Search query string.
    """
    await self._cli._execute("search:open", params={"query": query})

query(query, *, path=None, limit=None, case=False, matches=False) async

Search the vault.

Parameters:

Name Type Description Default
query str

Search query string.

required
path str | None

Restrict search to files under this path.

None
limit int | None

Maximum number of results to return.

None
case bool

If True, perform case-sensitive search.

False
matches bool

If True, include match details in results.

False

Returns:

Type Description
list[dict[str, Any]]

List of search result dictionaries.

Source code in src/aiobsidian/cli/search.py
async def query(
    self,
    query: str,
    *,
    path: str | None = None,
    limit: int | None = None,
    case: bool = False,
    matches: bool = False,
) -> list[dict[str, Any]]:
    """Search the vault.

    Args:
        query: Search query string.
        path: Restrict search to files under this path.
        limit: Maximum number of results to return.
        case: If ``True``, perform case-sensitive search.
        matches: If ``True``, include match details in results.

    Returns:
        List of search result dictionaries.
    """
    params: dict[str, str] = {"query": query}
    if path is not None:
        params["path"] = path
    if limit is not None:
        params["limit"] = str(limit)
    flags: list[str] = []
    if case:
        flags.append("--case")
    if matches:
        flags.append("--matches")
    output = await self._cli._execute("search", params=params, flags=flags or None)
    result: list[dict[str, Any]] = json.loads(output)
    return result

context(query, *, lines=None, path=None, limit=None, case=False) async

Search the vault with surrounding context lines.

Parameters:

Name Type Description Default
query str

Search query string.

required
lines int | None

Number of context lines to include around matches.

None
path str | None

Restrict search to files under this path.

None
limit int | None

Maximum number of results to return.

None
case bool

If True, perform case-sensitive search.

False

Returns:

Type Description
list[dict[str, Any]]

List of search result dictionaries with context.

Source code in src/aiobsidian/cli/search.py
async def context(
    self,
    query: str,
    *,
    lines: int | None = None,
    path: str | None = None,
    limit: int | None = None,
    case: bool = False,
) -> list[dict[str, Any]]:
    """Search the vault with surrounding context lines.

    Args:
        query: Search query string.
        lines: Number of context lines to include around matches.
        path: Restrict search to files under this path.
        limit: Maximum number of results to return.
        case: If ``True``, perform case-sensitive search.

    Returns:
        List of search result dictionaries with context.
    """
    params: dict[str, str] = {"query": query}
    if lines is not None:
        params["lines"] = str(lines)
    if path is not None:
        params["path"] = path
    if limit is not None:
        params["limit"] = str(limit)
    flags = ["--case"] if case else None
    output = await self._cli._execute("search:context", params=params, flags=flags)
    result: list[dict[str, Any]] = json.loads(output)
    return result