Skip to content

Latest commit

 

History

History
555 lines (482 loc) · 56 KB

File metadata and controls

555 lines (482 loc) · 56 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 main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Search.QueryAsAdmin(ctx, components.SearchRequest{
        TrackingToken: apiclientgo.Pointer("trackingToken"),
        PageSize: apiclientgo.Pointer[int64](10),
        Query: "vacation policy",
        RequestOptions: &components.SearchRequestOptions{
            FacetFilters: []components.FacetFilter{
                components.FacetFilter{
                    FieldName: apiclientgo.Pointer("type"),
                    Values: []components.FacetFilterValue{
                        components.FacetFilterValue{
                            Value: apiclientgo.Pointer("article"),
                            RelationType: components.RelationTypeEquals.ToPointer(),
                        },
                        components.FacetFilterValue{
                            Value: apiclientgo.Pointer("document"),
                            RelationType: components.RelationTypeEquals.ToPointer(),
                        },
                    },
                },
                components.FacetFilter{
                    FieldName: apiclientgo.Pointer("department"),
                    Values: []components.FacetFilterValue{
                        components.FacetFilterValue{
                            Value: apiclientgo.Pointer("engineering"),
                            RelationType: components.RelationTypeEquals.ToPointer(),
                        },
                    },
                },
            },
            FacetBucketSize: 421489,
        },
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.SearchResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
searchRequest components.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"
}
]
}
]
}
}
locale *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.
opts []operations.Option The options for this request.

Response

*operations.AdminsearchResponse, error

Errors

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

Autocomplete

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

Example Usage

package main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Search.Autocomplete(ctx, components.AutocompleteRequest{
        TrackingToken: apiclientgo.Pointer("trackingToken"),
        Query: apiclientgo.Pointer("what is a que"),
        Datasource: apiclientgo.Pointer("GDRIVE"),
        ResultSize: apiclientgo.Pointer[int64](10),
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.AutocompleteResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
autocompleteRequest components.AutocompleteRequest ✔️ Autocomplete request {
"trackingToken": "trackingToken",
"query": "what is a que",
"datasource": "GDRIVE",
"resultSize": 10
}
locale *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.
opts []operations.Option The options for this request.

Response

*operations.AutocompleteResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

RetrieveFeed

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

Example Usage

package main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Search.RetrieveFeed(ctx, components.FeedRequest{
        TimeoutMillis: apiclientgo.Pointer[int64](5000),
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.FeedResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
feedRequest components.FeedRequest ✔️ Includes request params, client data and more for making user's feed.
locale *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.
opts []operations.Option The options for this request.

Response

*operations.FeedResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

Recommendations

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

Example Usage

package main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/types"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Search.Recommendations(ctx, components.RecommendationsRequest{
        SourceDocument: &components.Document{
            ContainerDocument: &components.Document{
                Metadata: &components.DocumentMetadata{
                    Datasource: apiclientgo.Pointer("datasource"),
                    ObjectType: apiclientgo.Pointer("Feature Request"),
                    Container: apiclientgo.Pointer("container"),
                    ParentID: apiclientgo.Pointer("JIRA_EN-1337"),
                    MimeType: apiclientgo.Pointer("mimeType"),
                    DocumentID: apiclientgo.Pointer("documentId"),
                    CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                    UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                    Author: &components.Person{
                        Name: "name",
                        ObfuscatedID: "<id>",
                    },
                    Components: []string{
                        "Backend",
                        "Networking",
                    },
                    Status: apiclientgo.Pointer("[\"Done\"]"),
                    CustomData: map[string]components.CustomDataValue{
                        "someCustomField": components.CustomDataValue{},
                    },
                },
            },
            ParentDocument: &components.Document{
                Metadata: &components.DocumentMetadata{
                    Datasource: apiclientgo.Pointer("datasource"),
                    ObjectType: apiclientgo.Pointer("Feature Request"),
                    Container: apiclientgo.Pointer("container"),
                    ParentID: apiclientgo.Pointer("JIRA_EN-1337"),
                    MimeType: apiclientgo.Pointer("mimeType"),
                    DocumentID: apiclientgo.Pointer("documentId"),
                    CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                    UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                    Author: &components.Person{
                        Name: "name",
                        ObfuscatedID: "<id>",
                    },
                    Components: []string{
                        "Backend",
                        "Networking",
                    },
                    Status: apiclientgo.Pointer("[\"Done\"]"),
                    CustomData: map[string]components.CustomDataValue{
                        "someCustomField": components.CustomDataValue{},
                    },
                },
            },
            Metadata: &components.DocumentMetadata{
                Datasource: apiclientgo.Pointer("datasource"),
                ObjectType: apiclientgo.Pointer("Feature Request"),
                Container: apiclientgo.Pointer("container"),
                ParentID: apiclientgo.Pointer("JIRA_EN-1337"),
                MimeType: apiclientgo.Pointer("mimeType"),
                DocumentID: apiclientgo.Pointer("documentId"),
                CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                Author: &components.Person{
                    Name: "name",
                    ObfuscatedID: "abc123",
                },
                Components: []string{
                    "Backend",
                    "Networking",
                },
                Status: apiclientgo.Pointer("[\"Done\"]"),
                CustomData: map[string]components.CustomDataValue{
                    "someCustomField": components.CustomDataValue{},
                },
            },
        },
        PageSize: apiclientgo.Pointer[int64](100),
        MaxSnippetSize: apiclientgo.Pointer[int64](400),
        RequestOptions: &components.RecommendationsRequestOptions{
            FacetFilterSets: []components.FacetFilterSet{
                components.FacetFilterSet{
                    Filters: []components.FacetFilter{
                        components.FacetFilter{
                            FieldName: apiclientgo.Pointer("type"),
                            Values: []components.FacetFilterValue{
                                components.FacetFilterValue{
                                    Value: apiclientgo.Pointer("Spreadsheet"),
                                    RelationType: components.RelationTypeEquals.ToPointer(),
                                },
                                components.FacetFilterValue{
                                    Value: apiclientgo.Pointer("Presentation"),
                                    RelationType: components.RelationTypeEquals.ToPointer(),
                                },
                            },
                        },
                    },
                },
                components.FacetFilterSet{
                    Filters: []components.FacetFilter{
                        components.FacetFilter{
                            FieldName: apiclientgo.Pointer("type"),
                            Values: []components.FacetFilterValue{
                                components.FacetFilterValue{
                                    Value: apiclientgo.Pointer("Spreadsheet"),
                                    RelationType: components.RelationTypeEquals.ToPointer(),
                                },
                                components.FacetFilterValue{
                                    Value: apiclientgo.Pointer("Presentation"),
                                    RelationType: components.RelationTypeEquals.ToPointer(),
                                },
                            },
                        },
                    },
                },
                components.FacetFilterSet{
                    Filters: []components.FacetFilter{
                        components.FacetFilter{
                            FieldName: apiclientgo.Pointer("type"),
                            Values: []components.FacetFilterValue{
                                components.FacetFilterValue{
                                    Value: apiclientgo.Pointer("Spreadsheet"),
                                    RelationType: components.RelationTypeEquals.ToPointer(),
                                },
                                components.FacetFilterValue{
                                    Value: apiclientgo.Pointer("Presentation"),
                                    RelationType: components.RelationTypeEquals.ToPointer(),
                                },
                            },
                        },
                    },
                },
            },
            Context: &components.Document{
                ContainerDocument: &components.Document{
                    Metadata: &components.DocumentMetadata{
                        Datasource: apiclientgo.Pointer("datasource"),
                        ObjectType: apiclientgo.Pointer("Feature Request"),
                        Container: apiclientgo.Pointer("container"),
                        ParentID: apiclientgo.Pointer("JIRA_EN-1337"),
                        MimeType: apiclientgo.Pointer("mimeType"),
                        DocumentID: apiclientgo.Pointer("documentId"),
                        CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                        UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                        Author: &components.Person{
                            Name: "name",
                            ObfuscatedID: "<id>",
                        },
                        Components: []string{
                            "Backend",
                            "Networking",
                        },
                        Status: apiclientgo.Pointer("[\"Done\"]"),
                        CustomData: map[string]components.CustomDataValue{
                            "someCustomField": components.CustomDataValue{},
                        },
                    },
                },
                ParentDocument: &components.Document{
                    Metadata: &components.DocumentMetadata{
                        Datasource: apiclientgo.Pointer("datasource"),
                        ObjectType: apiclientgo.Pointer("Feature Request"),
                        Container: apiclientgo.Pointer("container"),
                        ParentID: apiclientgo.Pointer("JIRA_EN-1337"),
                        MimeType: apiclientgo.Pointer("mimeType"),
                        DocumentID: apiclientgo.Pointer("documentId"),
                        CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                        UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                        Author: &components.Person{
                            Name: "name",
                            ObfuscatedID: "<id>",
                        },
                        Components: []string{
                            "Backend",
                            "Networking",
                        },
                        Status: apiclientgo.Pointer("[\"Done\"]"),
                        CustomData: map[string]components.CustomDataValue{
                            "someCustomField": components.CustomDataValue{},
                        },
                    },
                },
                Metadata: &components.DocumentMetadata{
                    Datasource: apiclientgo.Pointer("datasource"),
                    ObjectType: apiclientgo.Pointer("Feature Request"),
                    Container: apiclientgo.Pointer("container"),
                    ParentID: apiclientgo.Pointer("JIRA_EN-1337"),
                    MimeType: apiclientgo.Pointer("mimeType"),
                    DocumentID: apiclientgo.Pointer("documentId"),
                    CreateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                    UpdateTime: types.MustNewTimeFromString("2000-01-23T04:56:07.000Z"),
                    Author: &components.Person{
                        Name: "name",
                        ObfuscatedID: "abc123",
                    },
                    Components: []string{
                        "Backend",
                        "Networking",
                    },
                    Status: apiclientgo.Pointer("[\"Done\"]"),
                    CustomData: map[string]components.CustomDataValue{
                        "someCustomField": components.CustomDataValue{},
                    },
                },
            },
        },
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.ResultsResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
recommendationsRequest components.RecommendationsRequest ✔️ Recommendations request
locale *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.
opts []operations.Option The options for this request.

Response

*operations.RecommendationsResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

Query

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

Example Usage

package main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Search.Query(ctx, components.SearchRequest{
        TrackingToken: apiclientgo.Pointer("trackingToken"),
        PageSize: apiclientgo.Pointer[int64](10),
        Query: "vacation policy",
        RequestOptions: &components.SearchRequestOptions{
            FacetFilters: []components.FacetFilter{
                components.FacetFilter{
                    FieldName: apiclientgo.Pointer("type"),
                    Values: []components.FacetFilterValue{
                        components.FacetFilterValue{
                            Value: apiclientgo.Pointer("article"),
                            RelationType: components.RelationTypeEquals.ToPointer(),
                        },
                        components.FacetFilterValue{
                            Value: apiclientgo.Pointer("document"),
                            RelationType: components.RelationTypeEquals.ToPointer(),
                        },
                    },
                },
                components.FacetFilter{
                    FieldName: apiclientgo.Pointer("department"),
                    Values: []components.FacetFilterValue{
                        components.FacetFilterValue{
                            Value: apiclientgo.Pointer("engineering"),
                            RelationType: components.RelationTypeEquals.ToPointer(),
                        },
                    },
                },
            },
            FacetBucketSize: 400611,
        },
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.SearchResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
searchRequest components.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"
}
]
}
]
}
}
locale *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.
opts []operations.Option The options for this request.

Response

*operations.SearchResponse, error

Errors

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