diff --git a/app/models/serving_config.rb b/app/models/serving_config.rb new file mode 100644 index 0000000..9f87704 --- /dev/null +++ b/app/models/serving_config.rb @@ -0,0 +1,21 @@ +# Represents a serving config on Discovery Engine. +# +# A serving config is an endpoint on an engine that can be used for +# querying. Each serving config can have different configuration (in particular, different sets of +# active controls), which allows us to test out new configuration changes outside of the default +# serving config. +# +# see https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1beta/latest/Google-Cloud-DiscoveryEngine-V1beta-ServingConfig +ServingConfig = Data.define(:remote_resource_id) do + include DiscoveryEngineNameable + + # The default serving config automatically available on an engine + def self.default + new("default_search") + end + + def parent + # We only use a single engine in our architecture, so we can hardcode it here. + Engine.default + end +end diff --git a/app/services/discovery_engine/query/search.rb b/app/services/discovery_engine/query/search.rb index 0985405..94d4853 100644 --- a/app/services/discovery_engine/query/search.rb +++ b/app/services/discovery_engine/query/search.rb @@ -56,7 +56,7 @@ def query end def serving_config - Rails.configuration.discovery_engine_serving_config + ServingConfig.default.name end def page_size diff --git a/config/application.rb b/config/application.rb index 62f73e8..67ba14e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,7 +18,6 @@ class Application < Rails::Application # Google Discovery Engine configuration config.discovery_engine_default_collection_name = ENV.fetch("DISCOVERY_ENGINE_DEFAULT_COLLECTION_NAME") - config.discovery_engine_serving_config = ENV.fetch("DISCOVERY_ENGINE_SERVING_CONFIG") config.google_cloud_project_id = ENV.fetch("GOOGLE_CLOUD_PROJECT_ID") # Document sync configuration diff --git a/spec/models/serving_config_spec.rb b/spec/models/serving_config_spec.rb new file mode 100644 index 0000000..1545bc1 --- /dev/null +++ b/spec/models/serving_config_spec.rb @@ -0,0 +1,15 @@ +RSpec.describe ServingConfig do + subject(:serving_config) { described_class.new("my-serving-config") } + + describe ".default" do + it "returns the default serving config" do + expect(described_class.default).to eq(described_class.new("default_search")) + end + end + + describe "#name" do + it "returns the fully qualified name of the serving config" do + expect(subject.name).to eq("[collection]/engines/govuk/servingConfigs/my-serving-config") + end + end +end diff --git a/spec/services/discovery_engine/query/search_spec.rb b/spec/services/discovery_engine/query/search_spec.rb index 324e4c3..ec3353e 100644 --- a/spec/services/discovery_engine/query/search_spec.rb +++ b/spec/services/discovery_engine/query/search_spec.rb @@ -16,8 +16,6 @@ end before do - allow(Rails.configuration).to receive(:discovery_engine_serving_config) - .and_return("serving-config-path") allow(DiscoveryEngine::Query::Filters).to receive(:new).and_return(filters) end @@ -52,7 +50,7 @@ it "calls the client with the expected parameters" do expect(client).to have_received(:search).with( - serving_config: "serving-config-path", + serving_config: ServingConfig.default.name, query: "garden centres", offset: 0, page_size: 10, @@ -76,7 +74,7 @@ it "calls the client with the expected parameters" do expect(client).to have_received(:search).with( - serving_config: "serving-config-path", + serving_config: ServingConfig.default.name, query: "garden centres", offset: 11, page_size: 22,