Global Search

The dashboard’s global search: find the Smarter resources of every kind that a user may read.

The search box on the dashboard sends one query, which is one of:

  • text, e.g. support: resources whose name or description contains it, ignoring case, or that have the tag support;

  • a tag, tag:production: resources that have the tag production;

  • an annotation selector requirement, e.g. acme.com/crm-account-id=A-10042 or !acme.com/archived: see smarter.lib.annotation.selectors. Text that contains =, or begins with !, is a requirement. Text with a / and no spaces is a requirement when it is a valid annotation key, e.g. acme.com/crm-account-id, and text otherwise.

Every list of the web console (smarter.lib.django.listview.listview_registry()) is searched with its list api’s own queryset, so a user finds only what their lists show them, and with its own serializer, so each result links to the same page as the list does. The results are grouped by list, a few per list, each group with a link to its list, narrowed by the same query.

class smarter.apps.dashboard.search.GlobalSearchGroup(**data)[source]

Bases: GlobalSearchModel

The resources of one list that match the query.

count: int
label: str
model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

results: list[GlobalSearchResult]
url: str
class smarter.apps.dashboard.search.GlobalSearchResponse(**data)[source]

Bases: GlobalSearchModel

The response of the global search.

count: int
error: str
groups: list[GlobalSearchGroup]
mode: Literal['text', 'tag', 'annotation']
model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

query: str
class smarter.apps.dashboard.search.GlobalSearchResult(**data)[source]

Bases: GlobalSearchModel

One resource that matches the query.

description: str
model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
url: str
smarter.apps.dashboard.search.detail_page_url(entry, row)[source]

Return the url of a resource’s list, narrowed by its name, with the resource’s detail open.

The list’s TabbedListView opens the detail of ?detail=<record locator>: the resource’s manifest, what it uses and what uses it, beside its own fields. The record locator is the last part of the row’s detailUrl, which smarter.apps.account.serializers.MetaDataWithOwnershipModelSerializer adds.

Parameters:
  • entry (ListviewEntry) – The resource’s list.

  • row (dict) – The serialized resource.

Return type:

str | None

Returns:

The url, e.g. /secret/?search=openai_api_key&detail=secret-rMTAwx, or None if the row has no detail.

Search every list of the web console for the resources that match a query and that the user may read.

Parameters:
Return type:

GlobalSearchResponse

Returns:

The results, grouped by list, the lists with the most matches first.

smarter.apps.dashboard.search.list_url(entry, mode, value)[source]

Return the url of a list’s page, narrowed by the query, as its TabbedListView reads it.

Parameters:
  • entry (ListviewEntry) – The list.

  • mode (Literal['text', 'tag', 'annotation']) – How the query was understood.

  • value (str) – The value to search for.

Return type:

str

Returns:

The url, e.g. /guardrail/?tag=production.

smarter.apps.dashboard.search.parse_query(query)[source]

Return how a query is understood: its mode, the value to search for, and an error, if any.

Example:

parse_query("support")              # ("text", "support", "")
parse_query("tag:production")       # ("tag", "production", "")
parse_query("acme.com/crm-id=A-1")  # ("annotation", "acme.com/crm-id=A-1", "")
parse_query("https://example.com")  # ("text", "https://example.com", "")
Parameters:

query (str) – The query, as typed.

Return type:

tuple[Literal['text', 'tag', 'annotation'], str, str]

Returns:

The mode, the value, and why the query is invalid, or an empty string.

API view of the dashboard’s global search.

The dashboard’s search box posts its query here, and shows the resources of every kind that match it and that the user may read, grouped by list. See smarter.apps.dashboard.search.

class smarter.apps.dashboard.views.views.api.search.GlobalSearchView(**kwargs)[source]

Bases: SmarterAuthenticatedWebView

Search every list of the web console.

The query is the query of the json request body, e.g. {"query": "tag:production"}, or the query query parameter of a GET.

Response shape, a dumped GlobalSearchResponse:

{
    "query": "tag:production",
    "mode": "tag",
    "error": "",
    "count": 3,
    "groups": [
        {
            "label": "Guardrails",
            "count": 3,
            "url": "/guardrail/?tag=production",
            "results": [{"name": "pii_redaction", "description": "...", "url": "/guardrail/guardrails/rMTAwx/"}]
        }
    ]
}
get(request, *args, **kwargs)[source]

Return the same json as a POST, so that the search can be browsed.

Return type:

JsonResponse

post(request, *args, **kwargs)[source]

Return the resources that match the query, grouped by list.

Return type:

JsonResponse

query_of(request)[source]

Return the query, from the json body, or the query parameters.

Return type:

str