Skip to content

Latest commit

 

History

History
633 lines (554 loc) · 94.2 KB

File metadata and controls

633 lines (554 loc) · 94.2 KB

Client.Search

Overview

Available Operations

query_as_admin

Retrieves results for search query without respect for permissions. This is available only to privileged users.

Example Usage

from glean.api_client import Glean, models
from glean.api_client.utils import parse_datetime
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.search.query_as_admin(query="vacation policy", tracking_token="trackingToken", source_document=models.Document(
        container_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        parent_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        metadata=models.DocumentMetadata(
            datasource="datasource",
            object_type="Feature Request",
            container="container",
            parent_id="JIRA_EN-1337",
            mime_type="mimeType",
            document_id="documentId",
            create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            author=models.Person(
                name="name",
                obfuscated_id="<id>",
            ),
            components=[
                "Backend",
                "Networking",
            ],
            status="[\"Done\"]",
            custom_data={
                "someCustomField": models.CustomDataValue(),
            },
        ),
    ), page_size=10, max_snippet_size=400, input_details={
        "has_copy_paste": True,
    }, request_options=models.SearchRequestOptions(
        facet_filters=[
            models.FacetFilter(
                field_name="type",
                values=[
                    models.FacetFilterValue(
                        value="article",
                        relation_type=models.RelationType.EQUALS,
                    ),
                    models.FacetFilterValue(
                        value="document",
                        relation_type=models.RelationType.EQUALS,
                    ),
                ],
            ),
            models.FacetFilter(
                field_name="department",
                values=[
                    models.FacetFilterValue(
                        value="engineering",
                        relation_type=models.RelationType.EQUALS,
                    ),
                ],
            ),
        ],
        facet_bucket_size=723824,
    ), timeout_millis=5000)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
query str ✔️ The search terms. vacation policy
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
timestamp date The ISO 8601 timestamp associated with the client request.
tracking_token Optional[str] A previously received trackingToken for a search associated with the same query. Useful for more requests and requests for other tabs.
session_info Optional[models.SessionInfo] N/A
source_document Optional[models.Document] N/A
page_size Optional[int] Hint to the server about how many results to send back. Server may return less or more. Structured results and clustered results don't count towards pageSize. 100
max_snippet_size Optional[int] Hint to the server about how many characters long a snippet may be. Server may return less or more. 400
cursor Optional[str] Pagination cursor. A previously received opaque token representing the position in the overall results at which to start.
result_tab_ids List[str] The unique IDs of the result tabs for which to fetch results. This will have precedence over datasource filters if both are specified and in conflict.
input_details Optional[models.SearchRequestInputDetails] N/A {
"hasCopyPaste": true
}
request_options Optional[models.SearchRequestOptions] N/A {
"datasourceFilter": "JIRA",
"datasourcesFilter": [
"JIRA"
],
"queryOverridesFacetFilters": true,
"facetFilters": [
{
"fieldName": "fieldName",
"values": [
"fieldValues",
"fieldValues"
]
},
{
"fieldName": "fieldName",
"values": [
"fieldValues",
"fieldValues"
]
}
]
}
timeout_millis Optional[int] Timeout in milliseconds for the request. A 408 error will be returned if handling the request takes longer. 5000
disable_spellcheck Optional[bool] Whether or not to disable spellcheck.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.SearchResponse

Errors

Error Type Status Code Content Type
errors.GleanDataError 403, 422 application/json
errors.GleanError 4XX, 5XX */*

autocomplete

Retrieve query suggestions, operators and documents for the given partially typed query.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.search.autocomplete(tracking_token="trackingToken", query="what is a que", datasource="GDRIVE", result_size=10, auth_tokens=[
        {
            "access_token": "123abc",
            "datasource": "gmail",
            "scope": "email profile https://www.googleapis.com/auth/gmail.readonly",
            "token_type": "Bearer",
            "auth_user": "1",
        },
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
tracking_token Optional[str] N/A
session_info Optional[models.SessionInfo] N/A
query Optional[str] Partially typed query. San Fra
datasources_filter List[str] Filter results to only those relevant to one or more datasources (e.g. jira, gdrive). Results are unfiltered if missing.
datasource Optional[str] Filter to only return results relevant to the given datasource.
result_types List[models.AutocompleteRequestResultType] Filter to only return results of the given type(s). All types may be returned if omitted.
result_size Optional[int] Maximum number of results to be returned. If no value is provided, the backend will cap at 200.
10
auth_tokens List[models.AuthToken] Auth tokens which may be used for federated results.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.AutocompleteResponse

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*

retrieve_feed

The personalized feed/home includes different types of contents including suggestions, recents, calendar events and many more.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.search.retrieve_feed(timeout_millis=5000)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
categories List[models.FeedRequestCategory] Categories of content requested. An allowlist gives flexibility to request content separately or together.
request_options Optional[models.FeedRequestOptions] N/A
timeout_millis Optional[int] Timeout in milliseconds for the request. A 408 error will be returned if handling the request takes longer. 5000
session_info Optional[models.SessionInfo] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.FeedResponse

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*

recommendations

Retrieve recommended documents for the given URL or Glean Document ID.

Example Usage

from glean.api_client import Glean, models
from glean.api_client.utils import parse_datetime
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.search.recommendations(source_document=models.Document(
        container_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        parent_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        metadata=models.DocumentMetadata(
            datasource="datasource",
            object_type="Feature Request",
            container="container",
            parent_id="JIRA_EN-1337",
            mime_type="mimeType",
            document_id="documentId",
            create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            author=models.Person(
                name="name",
                obfuscated_id="<id>",
            ),
            components=[
                "Backend",
                "Networking",
            ],
            status="[\"Done\"]",
            custom_data={
                "someCustomField": models.CustomDataValue(),
            },
        ),
    ), page_size=100, max_snippet_size=400, request_options=models.RecommendationsRequestOptions(
        facet_filter_sets=[
            models.FacetFilterSet(
                filters=[
                    models.FacetFilter(
                        field_name="type",
                        values=[
                            models.FacetFilterValue(
                                value="Spreadsheet",
                                relation_type=models.RelationType.EQUALS,
                            ),
                            models.FacetFilterValue(
                                value="Presentation",
                                relation_type=models.RelationType.EQUALS,
                            ),
                        ],
                    ),
                ],
            ),
        ],
        context=models.Document(
            container_document=models.Document(
                metadata=models.DocumentMetadata(
                    datasource="datasource",
                    object_type="Feature Request",
                    container="container",
                    parent_id="JIRA_EN-1337",
                    mime_type="mimeType",
                    document_id="documentId",
                    create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                    update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                    author=models.Person(
                        name="name",
                        obfuscated_id="<id>",
                    ),
                    components=[
                        "Backend",
                        "Networking",
                    ],
                    status="[\"Done\"]",
                    custom_data={
                        "someCustomField": models.CustomDataValue(),
                    },
                ),
            ),
            parent_document=models.Document(
                metadata=models.DocumentMetadata(
                    datasource="datasource",
                    object_type="Feature Request",
                    container="container",
                    parent_id="JIRA_EN-1337",
                    mime_type="mimeType",
                    document_id="documentId",
                    create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                    update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                    author=models.Person(
                        name="name",
                        obfuscated_id="<id>",
                    ),
                    components=[
                        "Backend",
                        "Networking",
                    ],
                    status="[\"Done\"]",
                    custom_data={
                        "someCustomField": models.CustomDataValue(),
                    },
                ),
            ),
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
    ))

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
timestamp date The ISO 8601 timestamp associated with the client request.
tracking_token Optional[str] A previously received trackingToken for a search associated with the same query. Useful for more requests and requests for other tabs.
session_info Optional[models.SessionInfo] N/A
source_document Optional[models.Document] N/A
page_size Optional[int] Hint to the server about how many results to send back. Server may return less or more. Structured results and clustered results don't count towards pageSize. 100
max_snippet_size Optional[int] Hint to the server about how many characters long a snippet may be. Server may return less or more. 400
recommendation_document_spec Optional[models.DocumentSpecUnion] N/A
request_options Optional[models.RecommendationsRequestOptions] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ResultsResponse

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*

query

Retrieve results from the index for the given query and filters.

Example Usage

from glean.api_client import Glean, models
from glean.api_client.utils import parse_datetime
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.search.query(query="vacation policy", tracking_token="trackingToken", source_document=models.Document(
        container_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        parent_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        metadata=models.DocumentMetadata(
            datasource="datasource",
            object_type="Feature Request",
            container="container",
            parent_id="JIRA_EN-1337",
            mime_type="mimeType",
            document_id="documentId",
            create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            author=models.Person(
                name="name",
                obfuscated_id="<id>",
            ),
            components=[
                "Backend",
                "Networking",
            ],
            status="[\"Done\"]",
            custom_data={
                "someCustomField": models.CustomDataValue(),
            },
        ),
    ), page_size=10, max_snippet_size=400, input_details={
        "has_copy_paste": True,
    }, request_options=models.SearchRequestOptions(
        facet_filters=[
            models.FacetFilter(
                field_name="type",
                values=[
                    models.FacetFilterValue(
                        value="article",
                        relation_type=models.RelationType.EQUALS,
                    ),
                    models.FacetFilterValue(
                        value="document",
                        relation_type=models.RelationType.EQUALS,
                    ),
                ],
            ),
            models.FacetFilter(
                field_name="department",
                values=[
                    models.FacetFilterValue(
                        value="engineering",
                        relation_type=models.RelationType.EQUALS,
                    ),
                ],
            ),
        ],
        facet_bucket_size=939520,
    ), timeout_millis=5000)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
query str ✔️ The search terms. vacation policy
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
timestamp date The ISO 8601 timestamp associated with the client request.
tracking_token Optional[str] A previously received trackingToken for a search associated with the same query. Useful for more requests and requests for other tabs.
session_info Optional[models.SessionInfo] N/A
source_document Optional[models.Document] N/A
page_size Optional[int] Hint to the server about how many results to send back. Server may return less or more. Structured results and clustered results don't count towards pageSize. 100
max_snippet_size Optional[int] Hint to the server about how many characters long a snippet may be. Server may return less or more. 400
cursor Optional[str] Pagination cursor. A previously received opaque token representing the position in the overall results at which to start.
result_tab_ids List[str] The unique IDs of the result tabs for which to fetch results. This will have precedence over datasource filters if both are specified and in conflict.
input_details Optional[models.SearchRequestInputDetails] N/A {
"hasCopyPaste": true
}
request_options Optional[models.SearchRequestOptions] N/A {
"datasourceFilter": "JIRA",
"datasourcesFilter": [
"JIRA"
],
"queryOverridesFacetFilters": true,
"facetFilters": [
{
"fieldName": "fieldName",
"values": [
"fieldValues",
"fieldValues"
]
},
{
"fieldName": "fieldName",
"values": [
"fieldValues",
"fieldValues"
]
}
]
}
timeout_millis Optional[int] Timeout in milliseconds for the request. A 408 error will be returned if handling the request takes longer. 5000
disable_spellcheck Optional[bool] Whether or not to disable spellcheck.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.SearchResponse

Errors

Error Type Status Code Content Type
errors.GleanDataError 403, 422 application/json
errors.GleanError 4XX, 5XX */*