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 tagsupport;a tag,
tag:production: resources that have the tagproduction;an annotation selector requirement, e.g.
acme.com/crm-account-id=A-10042or!acme.com/archived: seesmarter.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:
GlobalSearchModelThe resources of one list that match the query.
- 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]
- class smarter.apps.dashboard.search.GlobalSearchResponse(**data)[source]
Bases:
GlobalSearchModelThe response of the global search.
- groups: list[GlobalSearchGroup]
- 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].
- class smarter.apps.dashboard.search.GlobalSearchResult(**data)[source]
Bases:
GlobalSearchModelOne resource that matches the query.
- 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].
- 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’sdetailUrl, whichsmarter.apps.account.serializers.MetaDataWithOwnershipModelSerializeradds.- Parameters:
entry (
ListviewEntry) – The resource’s list.row (
dict) – The serialized resource.
- Return type:
- Returns:
The url, e.g.
/secret/?search=openai_api_key&detail=secret-rMTAwx, or None if the row has no detail.
- smarter.apps.dashboard.search.global_search(user, query, entries=None)[source]
Search every list of the web console for the resources that match a query and that the user may read.
- Parameters:
user – The authenticated user.
query (
str) – The query, as typed. Seeparse_query().entries (
tuple[ListviewEntry,...] |None) – The lists to search. Every list, by default.
- Return type:
- 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:
- 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", "")
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:
SmarterAuthenticatedWebViewSearch every list of the web console.
The query is the
queryof the json request body, e.g.{"query": "tag:production"}, or thequeryquery 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: