Discovery Engine v1beta API - Class SearchServiceClient (1.0.0-beta15)

public abstract class SearchServiceClient

Reference documentation and code samples for the Discovery Engine v1beta API class SearchServiceClient.

SearchService client wrapper, for convenient use.

Inheritance

object > SearchServiceClient

Derived Types

Namespace

Google.Cloud.DiscoveryEngine.V1Beta

Assembly

Google.Cloud.DiscoveryEngine.V1Beta.dll

Remarks

Service for search.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the SearchService service, which is a host of "discoveryengine.googleapis.com" and a port of 443.

Property Value
Type Description
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default SearchService scopes.

Property Value
Type Description
IReadOnlyListstring
Remarks

The default SearchService scopes are:

GrpcClient

public virtual SearchService.SearchServiceClient GrpcClient { get; }

The underlying gRPC SearchService client

Property Value
Type Description
SearchServiceSearchServiceClient

LocationsClient

public virtual LocationsClient LocationsClient { get; }

The LocationsClient associated with this client.

Property Value
Type Description
LocationsClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
Type Description
ServiceMetadata

Methods

Create()

public static SearchServiceClient Create()

Synchronously creates a SearchServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use SearchServiceClientBuilder.

Returns
Type Description
SearchServiceClient

The created SearchServiceClient.

CreateAsync(CancellationToken)

public static Task<SearchServiceClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a SearchServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use SearchServiceClientBuilder.

Parameter
Name Description
cancellationToken CancellationToken

The CancellationToken to use while creating the client.

Returns
Type Description
TaskSearchServiceClient

The task representing the created SearchServiceClient.

Search(SearchRequest, CallSettings)

public virtual PagedEnumerable<SearchResponse, SearchResponse.Types.SearchResult> Search(SearchRequest request, CallSettings callSettings = null)

Performs a search.

Parameters
Name Description
request SearchRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
PagedEnumerableSearchResponseSearchResponseTypesSearchResult

A pageable sequence of SearchResponse.Types.SearchResult resources.

Example
// Create client
SearchServiceClient searchServiceClient = SearchServiceClient.Create();
// Initialize request argument(s)
SearchRequest request = new SearchRequest
{
    ServingConfigAsServingConfigName = ServingConfigName.FromProjectLocationDataStoreServingConfig("[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[SERVING_CONFIG]"),
    BranchAsBranchName = BranchName.FromProjectLocationDataStoreBranch("[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]"),
    Query = "",
    Offset = 0,
    Filter = "",
    OrderBy = "",
    FacetSpecs =
    {
        new SearchRequest.Types.FacetSpec(),
    },
    BoostSpec = new SearchRequest.Types.BoostSpec(),
    Params = { { "", new Value() }, },
    QueryExpansionSpec = new SearchRequest.Types.QueryExpansionSpec(),
    SpellCorrectionSpec = new SearchRequest.Types.SpellCorrectionSpec(),
    UserPseudoId = "",
    ImageQuery = new SearchRequest.Types.ImageQuery(),
    SafeSearch = false,
    UserInfo = new UserInfo(),
    UserLabels = { { "", "" }, },
    EmbeddingSpec = new SearchRequest.Types.EmbeddingSpec(),
    ContentSearchSpec = new SearchRequest.Types.ContentSearchSpec(),
    RankingExpression = "",
    CanonicalFilter = "",
    DataStoreSpecs =
    {
        new SearchRequest.Types.DataStoreSpec(),
    },
};
// Make the request
PagedEnumerable<SearchResponse, SearchResponse.Types.SearchResult> response = searchServiceClient.Search(request);

// Iterate over all response items, lazily performing RPCs as required
foreach (SearchResponse.Types.SearchResult item in response)
{
    // Do something with each item
    Console.WriteLine(item);
}

// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (SearchResponse page in response.AsRawResponses())
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (SearchResponse.Types.SearchResult item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
}

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<SearchResponse.Types.SearchResult> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (SearchResponse.Types.SearchResult item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

SearchAsync(SearchRequest, CallSettings)

public virtual PagedAsyncEnumerable<SearchResponse, SearchResponse.Types.SearchResult> SearchAsync(SearchRequest request, CallSettings callSettings = null)

Performs a search.

Parameters
Name Description
request SearchRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
PagedAsyncEnumerableSearchResponseSearchResponseTypesSearchResult

A pageable asynchronous sequence of SearchResponse.Types.SearchResult resources.

Example
// Create client
SearchServiceClient searchServiceClient = await SearchServiceClient.CreateAsync();
// Initialize request argument(s)
SearchRequest request = new SearchRequest
{
    ServingConfigAsServingConfigName = ServingConfigName.FromProjectLocationDataStoreServingConfig("[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[SERVING_CONFIG]"),
    BranchAsBranchName = BranchName.FromProjectLocationDataStoreBranch("[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]"),
    Query = "",
    Offset = 0,
    Filter = "",
    OrderBy = "",
    FacetSpecs =
    {
        new SearchRequest.Types.FacetSpec(),
    },
    BoostSpec = new SearchRequest.Types.BoostSpec(),
    Params = { { "", new Value() }, },
    QueryExpansionSpec = new SearchRequest.Types.QueryExpansionSpec(),
    SpellCorrectionSpec = new SearchRequest.Types.SpellCorrectionSpec(),
    UserPseudoId = "",
    ImageQuery = new SearchRequest.Types.ImageQuery(),
    SafeSearch = false,
    UserInfo = new UserInfo(),
    UserLabels = { { "", "" }, },
    EmbeddingSpec = new SearchRequest.Types.EmbeddingSpec(),
    ContentSearchSpec = new SearchRequest.Types.ContentSearchSpec(),
    RankingExpression = "",
    CanonicalFilter = "",
    DataStoreSpecs =
    {
        new SearchRequest.Types.DataStoreSpec(),
    },
};
// Make the request
PagedAsyncEnumerable<SearchResponse, SearchResponse.Types.SearchResult> response = searchServiceClient.SearchAsync(request);

// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((SearchResponse.Types.SearchResult item) =>
{
    // Do something with each item
    Console.WriteLine(item);
});

// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((SearchResponse page) =>
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (SearchResponse.Types.SearchResult item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
});

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<SearchResponse.Types.SearchResult> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (SearchResponse.Types.SearchResult item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
Type Description
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.