Skip to content

Commit 9fb2e15

Browse files
feat: conversational search public SDK (#30955)
PiperOrigin-RevId: 803583303 Source-Link: googleapis/googleapis@1f0e127 Source-Link: googleapis/googleapis-gen@6ed3ac3 Copy-Tag: eyJwIjoiZ29vZ2xlLWNsb3VkLXJldGFpbC8uT3dsQm90LnlhbWwiLCJoIjoiNmVkM2FjM2E5ZDY1ODJmNzZmZDc0ZGI1NTgwZTM2YWU3MmZhMDA5ZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent ae38d4f commit 9fb2e15

2 files changed

Lines changed: 189 additions & 94 deletions

File tree

google-cloud-retail/lib/google/cloud/retail.rb

Lines changed: 147 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,153 @@ def self.control_service_available? version: :v2, transport: :grpc
329329
false
330330
end
331331

332+
##
333+
# Create a new client object for SearchService.
334+
#
335+
# By default, this returns an instance of
336+
# [Google::Cloud::Retail::V2::SearchService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-SearchService-Client)
337+
# for a gRPC client for version V2 of the API.
338+
# However, you can specify a different API version by passing it in the
339+
# `version` parameter. If the SearchService service is
340+
# supported by that API version, and the corresponding gem is available, the
341+
# appropriate versioned client will be returned.
342+
# You can also specify a different transport by passing `:rest` or `:grpc` in
343+
# the `transport` parameter.
344+
#
345+
# Raises an exception if the currently installed versioned client gem for the
346+
# given API version does not support the given transport of the SearchService service.
347+
# You can determine whether the method will succeed by calling
348+
# {Google::Cloud::Retail.search_service_available?}.
349+
#
350+
# ## About SearchService
351+
#
352+
# Service for search.
353+
#
354+
# This feature is only available for users who have Retail Search enabled.
355+
# Enable Retail Search on Cloud Console before using this feature.
356+
#
357+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
358+
# Defaults to `:v2`.
359+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
360+
# @return [::Object] A client object for the specified version.
361+
#
362+
def self.search_service version: :v2, transport: :grpc, &block
363+
require "google/cloud/retail/#{version.to_s.downcase}"
364+
365+
package_name = Google::Cloud::Retail
366+
.constants
367+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
368+
.first
369+
service_module = Google::Cloud::Retail.const_get(package_name).const_get(:SearchService)
370+
service_module = service_module.const_get(:Rest) if transport == :rest
371+
service_module.const_get(:Client).new(&block)
372+
end
373+
374+
##
375+
# Determines whether the SearchService service is supported by the current client.
376+
# If true, you can retrieve a client object by calling {Google::Cloud::Retail.search_service}.
377+
# If false, that method will raise an exception. This could happen if the given
378+
# API version does not exist or does not support the SearchService service,
379+
# or if the versioned client gem needs an update to support the SearchService service.
380+
#
381+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
382+
# Defaults to `:v2`.
383+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
384+
# @return [boolean] Whether the service is available.
385+
#
386+
def self.search_service_available? version: :v2, transport: :grpc
387+
require "google/cloud/retail/#{version.to_s.downcase}"
388+
package_name = Google::Cloud::Retail
389+
.constants
390+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
391+
.first
392+
return false unless package_name
393+
service_module = Google::Cloud::Retail.const_get package_name
394+
return false unless service_module.const_defined? :SearchService
395+
service_module = service_module.const_get :SearchService
396+
if transport == :rest
397+
return false unless service_module.const_defined? :Rest
398+
service_module = service_module.const_get :Rest
399+
end
400+
service_module.const_defined? :Client
401+
rescue ::LoadError
402+
false
403+
end
404+
405+
##
406+
# Create a new client object for ConversationalSearchService.
407+
#
408+
# By default, this returns an instance of
409+
# [Google::Cloud::Retail::V2::ConversationalSearchService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-ConversationalSearchService-Client)
410+
# for a gRPC client for version V2 of the API.
411+
# However, you can specify a different API version by passing it in the
412+
# `version` parameter. If the ConversationalSearchService service is
413+
# supported by that API version, and the corresponding gem is available, the
414+
# appropriate versioned client will be returned.
415+
# You can also specify a different transport by passing `:rest` or `:grpc` in
416+
# the `transport` parameter.
417+
#
418+
# Raises an exception if the currently installed versioned client gem for the
419+
# given API version does not support the given transport of the ConversationalSearchService service.
420+
# You can determine whether the method will succeed by calling
421+
# {Google::Cloud::Retail.conversational_search_service_available?}.
422+
#
423+
# ## About ConversationalSearchService
424+
#
425+
# Service for retail conversational search.
426+
#
427+
# This feature is only available for users who have Retail Conversational
428+
# Search enabled. Enable Retail Conversational Search on Cloud Console
429+
# before using this feature.
430+
#
431+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
432+
# Defaults to `:v2`.
433+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
434+
# @return [::Object] A client object for the specified version.
435+
#
436+
def self.conversational_search_service version: :v2, transport: :grpc, &block
437+
require "google/cloud/retail/#{version.to_s.downcase}"
438+
439+
package_name = Google::Cloud::Retail
440+
.constants
441+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
442+
.first
443+
service_module = Google::Cloud::Retail.const_get(package_name).const_get(:ConversationalSearchService)
444+
service_module = service_module.const_get(:Rest) if transport == :rest
445+
service_module.const_get(:Client).new(&block)
446+
end
447+
448+
##
449+
# Determines whether the ConversationalSearchService service is supported by the current client.
450+
# If true, you can retrieve a client object by calling {Google::Cloud::Retail.conversational_search_service}.
451+
# If false, that method will raise an exception. This could happen if the given
452+
# API version does not exist or does not support the ConversationalSearchService service,
453+
# or if the versioned client gem needs an update to support the ConversationalSearchService service.
454+
#
455+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
456+
# Defaults to `:v2`.
457+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
458+
# @return [boolean] Whether the service is available.
459+
#
460+
def self.conversational_search_service_available? version: :v2, transport: :grpc
461+
require "google/cloud/retail/#{version.to_s.downcase}"
462+
package_name = Google::Cloud::Retail
463+
.constants
464+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
465+
.first
466+
return false unless package_name
467+
service_module = Google::Cloud::Retail.const_get package_name
468+
return false unless service_module.const_defined? :ConversationalSearchService
469+
service_module = service_module.const_get :ConversationalSearchService
470+
if transport == :rest
471+
return false unless service_module.const_defined? :Rest
472+
service_module = service_module.const_get :Rest
473+
end
474+
service_module.const_defined? :Client
475+
rescue ::LoadError
476+
false
477+
end
478+
332479
##
333480
# Create a new client object for GenerativeQuestionService.
334481
#
@@ -621,79 +768,6 @@ def self.product_service_available? version: :v2, transport: :grpc
621768
false
622769
end
623770

624-
##
625-
# Create a new client object for SearchService.
626-
#
627-
# By default, this returns an instance of
628-
# [Google::Cloud::Retail::V2::SearchService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-SearchService-Client)
629-
# for a gRPC client for version V2 of the API.
630-
# However, you can specify a different API version by passing it in the
631-
# `version` parameter. If the SearchService service is
632-
# supported by that API version, and the corresponding gem is available, the
633-
# appropriate versioned client will be returned.
634-
# You can also specify a different transport by passing `:rest` or `:grpc` in
635-
# the `transport` parameter.
636-
#
637-
# Raises an exception if the currently installed versioned client gem for the
638-
# given API version does not support the given transport of the SearchService service.
639-
# You can determine whether the method will succeed by calling
640-
# {Google::Cloud::Retail.search_service_available?}.
641-
#
642-
# ## About SearchService
643-
#
644-
# Service for search.
645-
#
646-
# This feature is only available for users who have Retail Search enabled.
647-
# Enable Retail Search on Cloud Console before using this feature.
648-
#
649-
# @param version [::String, ::Symbol] The API version to connect to. Optional.
650-
# Defaults to `:v2`.
651-
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
652-
# @return [::Object] A client object for the specified version.
653-
#
654-
def self.search_service version: :v2, transport: :grpc, &block
655-
require "google/cloud/retail/#{version.to_s.downcase}"
656-
657-
package_name = Google::Cloud::Retail
658-
.constants
659-
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
660-
.first
661-
service_module = Google::Cloud::Retail.const_get(package_name).const_get(:SearchService)
662-
service_module = service_module.const_get(:Rest) if transport == :rest
663-
service_module.const_get(:Client).new(&block)
664-
end
665-
666-
##
667-
# Determines whether the SearchService service is supported by the current client.
668-
# If true, you can retrieve a client object by calling {Google::Cloud::Retail.search_service}.
669-
# If false, that method will raise an exception. This could happen if the given
670-
# API version does not exist or does not support the SearchService service,
671-
# or if the versioned client gem needs an update to support the SearchService service.
672-
#
673-
# @param version [::String, ::Symbol] The API version to connect to. Optional.
674-
# Defaults to `:v2`.
675-
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
676-
# @return [boolean] Whether the service is available.
677-
#
678-
def self.search_service_available? version: :v2, transport: :grpc
679-
require "google/cloud/retail/#{version.to_s.downcase}"
680-
package_name = Google::Cloud::Retail
681-
.constants
682-
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
683-
.first
684-
return false unless package_name
685-
service_module = Google::Cloud::Retail.const_get package_name
686-
return false unless service_module.const_defined? :SearchService
687-
service_module = service_module.const_get :SearchService
688-
if transport == :rest
689-
return false unless service_module.const_defined? :Rest
690-
service_module = service_module.const_get :Rest
691-
end
692-
service_module.const_defined? :Client
693-
rescue ::LoadError
694-
false
695-
end
696-
697771
##
698772
# Create a new client object for ServingConfigService.
699773
#

google-cloud-retail/test/google/cloud/retail/client_test.rb

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,48 @@ def test_control_service_rest
125125
end
126126
end
127127

128+
def test_search_service_grpc
129+
skip unless Google::Cloud::Retail.search_service_available? transport: :grpc
130+
Gapic::ServiceStub.stub :new, DummyStub.new do
131+
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
132+
client = Google::Cloud::Retail.search_service transport: :grpc do |config|
133+
config.credentials = grpc_channel
134+
end
135+
assert_kind_of Google::Cloud::Retail::V2::SearchService::Client, client
136+
end
137+
end
138+
139+
def test_search_service_rest
140+
skip unless Google::Cloud::Retail.search_service_available? transport: :rest
141+
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
142+
client = Google::Cloud::Retail.search_service transport: :rest do |config|
143+
config.credentials = :dummy_credentials
144+
end
145+
assert_kind_of Google::Cloud::Retail::V2::SearchService::Rest::Client, client
146+
end
147+
end
148+
149+
def test_conversational_search_service_grpc
150+
skip unless Google::Cloud::Retail.conversational_search_service_available? transport: :grpc
151+
Gapic::ServiceStub.stub :new, DummyStub.new do
152+
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
153+
client = Google::Cloud::Retail.conversational_search_service transport: :grpc do |config|
154+
config.credentials = grpc_channel
155+
end
156+
assert_kind_of Google::Cloud::Retail::V2::ConversationalSearchService::Client, client
157+
end
158+
end
159+
160+
def test_conversational_search_service_rest
161+
skip unless Google::Cloud::Retail.conversational_search_service_available? transport: :rest
162+
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
163+
client = Google::Cloud::Retail.conversational_search_service transport: :rest do |config|
164+
config.credentials = :dummy_credentials
165+
end
166+
assert_kind_of Google::Cloud::Retail::V2::ConversationalSearchService::Rest::Client, client
167+
end
168+
end
169+
128170
def test_generative_question_service_grpc
129171
skip unless Google::Cloud::Retail.generative_question_service_available? transport: :grpc
130172
Gapic::ServiceStub.stub :new, DummyStub.new do
@@ -209,27 +251,6 @@ def test_product_service_rest
209251
end
210252
end
211253

212-
def test_search_service_grpc
213-
skip unless Google::Cloud::Retail.search_service_available? transport: :grpc
214-
Gapic::ServiceStub.stub :new, DummyStub.new do
215-
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
216-
client = Google::Cloud::Retail.search_service transport: :grpc do |config|
217-
config.credentials = grpc_channel
218-
end
219-
assert_kind_of Google::Cloud::Retail::V2::SearchService::Client, client
220-
end
221-
end
222-
223-
def test_search_service_rest
224-
skip unless Google::Cloud::Retail.search_service_available? transport: :rest
225-
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
226-
client = Google::Cloud::Retail.search_service transport: :rest do |config|
227-
config.credentials = :dummy_credentials
228-
end
229-
assert_kind_of Google::Cloud::Retail::V2::SearchService::Rest::Client, client
230-
end
231-
end
232-
233254
def test_serving_config_service_grpc
234255
skip unless Google::Cloud::Retail.serving_config_service_available? transport: :grpc
235256
Gapic::ServiceStub.stub :new, DummyStub.new do

0 commit comments

Comments
 (0)