Skip to content

Latest commit

 

History

History
527 lines (444 loc) · 46.3 KB

File metadata and controls

527 lines (444 loc) · 46.3 KB

Client.Search

Overview

Available Operations

queryAsAdmin

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

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.errors.GleanDataError;
import com.glean.api_client.glean_api_client.models.operations.AdminsearchResponse;
import java.lang.Exception;
import java.util.List;

public class Application {

    public static void main(String[] args) throws GleanDataError, Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        AdminsearchResponse res = sdk.client().search().queryAsAdmin()
                .searchRequest(SearchRequest.builder()
                    .query("vacation policy")
                    .trackingToken("trackingToken")
                    .pageSize(10L)
                    .requestOptions(SearchRequestOptions.builder()
                        .facetBucketSize(421489L)
                        .facetFilters(List.of(
                            FacetFilter.builder()
                                .fieldName("type")
                                .values(List.of(
                                    FacetFilterValue.builder()
                                        .value("article")
                                        .relationType(RelationType.EQUALS)
                                        .build(),
                                    FacetFilterValue.builder()
                                        .value("document")
                                        .relationType(RelationType.EQUALS)
                                        .build()))
                                .build(),
                            FacetFilter.builder()
                                .fieldName("department")
                                .values(List.of(
                                    FacetFilterValue.builder()
                                        .value("engineering")
                                        .relationType(RelationType.EQUALS)
                                        .build()))
                                .build()))
                        .build())
                    .build())
                .call();

        if (res.searchResponse().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description Example
locale Optional<String> 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.
searchRequest SearchRequest ✔️ Admin search request {
"trackingToken": "trackingToken",
"query": "vacation policy",
"pageSize": 10,
"requestOptions": {
"facetFilters": [
{
"fieldName": "type",
"values": [
{
"value": "article",
"relationType": "EQUALS"
},
{
"value": "document",
"relationType": "EQUALS"
}
]
},
{
"fieldName": "department",
"values": [
{
"value": "engineering",
"relationType": "EQUALS"
}
]
}
]
}
}

Response

AdminsearchResponse

Errors

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

autocomplete

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

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.AutocompleteRequest;
import com.glean.api_client.glean_api_client.models.operations.AutocompleteResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        AutocompleteResponse res = sdk.client().search().autocomplete()
                .autocompleteRequest(AutocompleteRequest.builder()
                    .trackingToken("trackingToken")
                    .query("what is a que")
                    .datasource("GDRIVE")
                    .resultSize(10L)
                    .build())
                .call();

        if (res.autocompleteResponse().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description Example
locale Optional<String> 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.
autocompleteRequest AutocompleteRequest ✔️ Autocomplete request {
"trackingToken": "trackingToken",
"query": "what is a que",
"datasource": "GDRIVE",
"resultSize": 10
}

Response

AutocompleteResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

retrieveFeed

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

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.FeedRequest;
import com.glean.api_client.glean_api_client.models.operations.FeedResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        FeedResponse res = sdk.client().search().retrieveFeed()
                .feedRequest(FeedRequest.builder()
                    .timeoutMillis(5000L)
                    .build())
                .call();

        if (res.feedResponse().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
locale Optional<String> 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.
feedRequest FeedRequest ✔️ Includes request params, client data and more for making user's feed.

Response

FeedResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

recommendations

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

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.operations.RecommendationsResponse;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        RecommendationsResponse res = sdk.client().search().recommendations()
                .recommendationsRequest(RecommendationsRequest.builder()
                    .sourceDocument(Document.builder()
                        .containerDocument(Document.builder()
                            .metadata(DocumentMetadata.builder()
                                .datasource("datasource")
                                .objectType("Feature Request")
                                .container("container")
                                .parentId("JIRA_EN-1337")
                                .mimeType("mimeType")
                                .documentId("documentId")
                                .createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                .updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                .author(Person.builder()
                                    .name("name")
                                    .obfuscatedId("<id>")
                                    .build())
                                .components(List.of(
                                    "Backend",
                                    "Networking"))
                                .status("[\"Done\"]")
                                .customData(Map.ofEntries(
                                    Map.entry("someCustomField", CustomDataValue.builder()
                                        .build())))
                                .build())
                            .build())
                        .parentDocument(Document.builder()
                            .metadata(DocumentMetadata.builder()
                                .datasource("datasource")
                                .objectType("Feature Request")
                                .container("container")
                                .parentId("JIRA_EN-1337")
                                .mimeType("mimeType")
                                .documentId("documentId")
                                .createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                .updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                .author(Person.builder()
                                    .name("name")
                                    .obfuscatedId("<id>")
                                    .build())
                                .components(List.of(
                                    "Backend",
                                    "Networking"))
                                .status("[\"Done\"]")
                                .customData(Map.ofEntries(
                                    Map.entry("someCustomField", CustomDataValue.builder()
                                        .build())))
                                .build())
                            .build())
                        .metadata(DocumentMetadata.builder()
                            .datasource("datasource")
                            .objectType("Feature Request")
                            .container("container")
                            .parentId("JIRA_EN-1337")
                            .mimeType("mimeType")
                            .documentId("documentId")
                            .createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                            .updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                            .author(Person.builder()
                                .name("name")
                                .obfuscatedId("abc123")
                                .build())
                            .components(List.of(
                                "Backend",
                                "Networking"))
                            .status("[\"Done\"]")
                            .customData(Map.ofEntries(
                                Map.entry("someCustomField", CustomDataValue.builder()
                                    .build())))
                            .build())
                        .build())
                    .pageSize(100L)
                    .maxSnippetSize(400L)
                    .requestOptions(RecommendationsRequestOptions.builder()
                        .facetFilterSets(List.of(
                            FacetFilterSet.builder()
                                .filters(List.of(
                                    FacetFilter.builder()
                                        .fieldName("type")
                                        .values(List.of(
                                            FacetFilterValue.builder()
                                                .value("Spreadsheet")
                                                .relationType(RelationType.EQUALS)
                                                .build(),
                                            FacetFilterValue.builder()
                                                .value("Presentation")
                                                .relationType(RelationType.EQUALS)
                                                .build()))
                                        .build()))
                                .build(),
                            FacetFilterSet.builder()
                                .filters(List.of(
                                    FacetFilter.builder()
                                        .fieldName("type")
                                        .values(List.of(
                                            FacetFilterValue.builder()
                                                .value("Spreadsheet")
                                                .relationType(RelationType.EQUALS)
                                                .build(),
                                            FacetFilterValue.builder()
                                                .value("Presentation")
                                                .relationType(RelationType.EQUALS)
                                                .build()))
                                        .build()))
                                .build(),
                            FacetFilterSet.builder()
                                .filters(List.of(
                                    FacetFilter.builder()
                                        .fieldName("type")
                                        .values(List.of(
                                            FacetFilterValue.builder()
                                                .value("Spreadsheet")
                                                .relationType(RelationType.EQUALS)
                                                .build(),
                                            FacetFilterValue.builder()
                                                .value("Presentation")
                                                .relationType(RelationType.EQUALS)
                                                .build()))
                                        .build()))
                                .build()))
                        .context(Document.builder()
                            .containerDocument(Document.builder()
                                .metadata(DocumentMetadata.builder()
                                    .datasource("datasource")
                                    .objectType("Feature Request")
                                    .container("container")
                                    .parentId("JIRA_EN-1337")
                                    .mimeType("mimeType")
                                    .documentId("documentId")
                                    .createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                    .updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                    .author(Person.builder()
                                        .name("name")
                                        .obfuscatedId("<id>")
                                        .build())
                                    .components(List.of(
                                        "Backend",
                                        "Networking"))
                                    .status("[\"Done\"]")
                                    .customData(Map.ofEntries(
                                        Map.entry("someCustomField", CustomDataValue.builder()
                                            .build())))
                                    .build())
                                .build())
                            .parentDocument(Document.builder()
                                .metadata(DocumentMetadata.builder()
                                    .datasource("datasource")
                                    .objectType("Feature Request")
                                    .container("container")
                                    .parentId("JIRA_EN-1337")
                                    .mimeType("mimeType")
                                    .documentId("documentId")
                                    .createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                    .updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                    .author(Person.builder()
                                        .name("name")
                                        .obfuscatedId("<id>")
                                        .build())
                                    .components(List.of(
                                        "Backend",
                                        "Networking"))
                                    .status("[\"Done\"]")
                                    .customData(Map.ofEntries(
                                        Map.entry("someCustomField", CustomDataValue.builder()
                                            .build())))
                                    .build())
                                .build())
                            .metadata(DocumentMetadata.builder()
                                .datasource("datasource")
                                .objectType("Feature Request")
                                .container("container")
                                .parentId("JIRA_EN-1337")
                                .mimeType("mimeType")
                                .documentId("documentId")
                                .createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                .updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
                                .author(Person.builder()
                                    .name("name")
                                    .obfuscatedId("abc123")
                                    .build())
                                .components(List.of(
                                    "Backend",
                                    "Networking"))
                                .status("[\"Done\"]")
                                .customData(Map.ofEntries(
                                    Map.entry("someCustomField", CustomDataValue.builder()
                                        .build())))
                                .build())
                            .build())
                        .build())
                    .build())
                .call();

        if (res.resultsResponse().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
locale Optional<String> 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.
recommendationsRequest RecommendationsRequest ✔️ Recommendations request

Response

RecommendationsResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

query

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

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.errors.GleanDataError;
import com.glean.api_client.glean_api_client.models.operations.SearchResponse;
import java.lang.Exception;
import java.util.List;

public class Application {

    public static void main(String[] args) throws GleanDataError, Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        SearchResponse res = sdk.client().search().query()
                .searchRequest(SearchRequest.builder()
                    .query("vacation policy")
                    .trackingToken("trackingToken")
                    .pageSize(10L)
                    .requestOptions(SearchRequestOptions.builder()
                        .facetBucketSize(400611L)
                        .facetFilters(List.of(
                            FacetFilter.builder()
                                .fieldName("type")
                                .values(List.of(
                                    FacetFilterValue.builder()
                                        .value("article")
                                        .relationType(RelationType.EQUALS)
                                        .build(),
                                    FacetFilterValue.builder()
                                        .value("document")
                                        .relationType(RelationType.EQUALS)
                                        .build()))
                                .build(),
                            FacetFilter.builder()
                                .fieldName("department")
                                .values(List.of(
                                    FacetFilterValue.builder()
                                        .value("engineering")
                                        .relationType(RelationType.EQUALS)
                                        .build()))
                                .build()))
                        .build())
                    .build())
                .call();

        if (res.searchResponse().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description Example
locale Optional<String> 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.
searchRequest SearchRequest ✔️ Search request {
"trackingToken": "trackingToken",
"query": "vacation policy",
"pageSize": 10,
"requestOptions": {
"facetFilters": [
{
"fieldName": "type",
"values": [
{
"value": "article",
"relationType": "EQUALS"
},
{
"value": "document",
"relationType": "EQUALS"
}
]
},
{
"fieldName": "department",
"values": [
{
"value": "engineering",
"relationType": "EQUALS"
}
]
}
]
}
}

Response

SearchResponse

Errors

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