Retail v2 API - Class SearchServiceClient (2.8.0)

public abstract class SearchServiceClient

Reference documentation and code samples for the Retail v2 API class SearchServiceClient.

SearchService client wrapper, for convenient use.

Inheritance

object > SearchServiceClient

Derived Types

Namespace

Google.Cloud.Retail.V2

Assembly

Google.Cloud.Retail.V2.dll

Remarks

Service for search.

This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

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

Property Value
TypeDescription
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default SearchService scopes.

Property Value
TypeDescription
IReadOnlyListstring
Remarks

The default SearchService scopes are:

GrpcClient

public virtual SearchService.SearchServiceClient GrpcClient { get; }

The underlying gRPC SearchService client

Property Value
TypeDescription
SearchServiceSearchServiceClient

LocationsClient

public virtual LocationsClient LocationsClient { get; }

The LocationsClient associated with this client.

Property Value
TypeDescription
LocationsClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
TypeDescription
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
TypeDescription
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
NameDescription
cancellationTokenCancellationToken

The CancellationToken to use while creating the client.

Returns
TypeDescription
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.

This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.

Parameters
NameDescription
requestSearchRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedEnumerableSearchResponseSearchResponseTypesSearchResult

A pageable sequence of SearchResponse.Types.SearchResult resources.

Example
// Create client
SearchServiceClient searchServiceClient = SearchServiceClient.Create();
// Initialize request argument(s)
SearchRequest request = new SearchRequest
{
    Placement = "",
    BranchAsBranchName = BranchName.FromProjectLocationCatalogBranch("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]"),
    Query = "",
    VisitorId = "",
    UserInfo = new UserInfo(),
    Offset = 0,
    Filter = "",
    OrderBy = "",
    FacetSpecs =
    {
        new SearchRequest.Types.FacetSpec(),
    },
    BoostSpec = new SearchRequest.Types.BoostSpec(),
    QueryExpansionSpec = new SearchRequest.Types.QueryExpansionSpec(),
    VariantRollupKeys = { "", },
    PageCategories = { "", },
    CanonicalFilter = "",
    SearchMode = SearchRequest.Types.SearchMode.Unspecified,
    PersonalizationSpec = new SearchRequest.Types.PersonalizationSpec(),
    Labels = { { "", "" }, },
    SpellCorrectionSpec = new SearchRequest.Types.SpellCorrectionSpec(),
    Entity = "",
};
// 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.

This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.

Parameters
NameDescription
requestSearchRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
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
{
    Placement = "",
    BranchAsBranchName = BranchName.FromProjectLocationCatalogBranch("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]"),
    Query = "",
    VisitorId = "",
    UserInfo = new UserInfo(),
    Offset = 0,
    Filter = "",
    OrderBy = "",
    FacetSpecs =
    {
        new SearchRequest.Types.FacetSpec(),
    },
    BoostSpec = new SearchRequest.Types.BoostSpec(),
    QueryExpansionSpec = new SearchRequest.Types.QueryExpansionSpec(),
    VariantRollupKeys = { "", },
    PageCategories = { "", },
    CanonicalFilter = "",
    SearchMode = SearchRequest.Types.SearchMode.Unspecified,
    PersonalizationSpec = new SearchRequest.Types.PersonalizationSpec(),
    Labels = { { "", "" }, },
    SpellCorrectionSpec = new SearchRequest.Types.SpellCorrectionSpec(),
    Entity = "",
};
// 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
TypeDescription
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.