Skip to content

Search Resource

SearchResource(client)

Bases: BaseResource

Search vault content using different query methods.

Source code in src/aiobsidian/rest/_base.py
def __init__(self, client: ObsidianClient) -> None:
    self._client = client

simple(query, *, context_length=100) async

Perform a simple text search across the vault.

Parameters:

Name Type Description Default
query str

The search query string.

required
context_length int

Number of context characters to include around each match.

100

Returns:

Type Description
list[SearchResult]

A list of SearchResult objects with matching files

list[SearchResult]

and context snippets.

Source code in src/aiobsidian/rest/search.py
async def simple(
    self,
    query: str,
    *,
    context_length: int = 100,
) -> list[SearchResult]:
    """Perform a simple text search across the vault.

    Args:
        query: The search query string.
        context_length: Number of context characters to include
            around each match.

    Returns:
        A list of `SearchResult` objects with matching files
        and context snippets.
    """
    response = await self._client.request(
        "POST",
        f"{self._BASE_URL}/simple/",
        params={"query": query, "contextLength": context_length},
    )
    return [SearchResult.model_validate(r) for r in response.json()]

dataview(dql) async

Search using a Dataview Query Language (DQL) expression.

Requires the Dataview plugin to be installed in Obsidian.

Parameters:

Name Type Description Default
dql str

A DQL query string (e.g. "TABLE file.name FROM #tag").

required

Returns:

Type Description
list[SearchResult]

A list of SearchResult objects.

Source code in src/aiobsidian/rest/search.py
async def dataview(self, dql: str) -> list[SearchResult]:
    """Search using a Dataview Query Language (DQL) expression.

    Requires the Dataview plugin to be installed in Obsidian.

    Args:
        dql: A DQL query string (e.g. `"TABLE file.name FROM #tag"`).

    Returns:
        A list of `SearchResult` objects.
    """
    response = await self._client.request(
        "POST",
        f"{self._BASE_URL}/",
        content=dql,
        headers={"Content-Type": ContentType.DATAVIEW_DQL},
    )
    return [SearchResult.model_validate(r) for r in response.json()]

jsonlogic(query) async

Search using a JsonLogic query object.

Parameters:

Name Type Description Default
query dict[str, Any]

A JsonLogic query dictionary (e.g. {"glob": ["*.md"]}).

required

Returns:

Type Description
list[SearchResult]

A list of SearchResult objects.

Source code in src/aiobsidian/rest/search.py
async def jsonlogic(self, query: dict[str, Any]) -> list[SearchResult]:
    """Search using a JsonLogic query object.

    Args:
        query: A JsonLogic query dictionary
            (e.g. `{"glob": ["*.md"]}`).

    Returns:
        A list of `SearchResult` objects.
    """
    response = await self._client.request(
        "POST",
        f"{self._BASE_URL}/",
        json=query,
        headers={"Content-Type": ContentType.JSONLOGIC},
    )
    return [SearchResult.model_validate(r) for r in response.json()]