diff --git a/README.md b/README.md index f5b045cc..ddd1517c 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ If you are using Maven, add this to your pom.xml file: If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-retail:2.0.19' +implementation 'com.google.cloud:google-cloud-retail:2.3.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-retail" % "2.0.19" +libraryDependencies += "com.google.cloud" % "google-cloud-retail" % "2.3.0" ``` ## Authentication diff --git a/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java b/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java index 23389950..935eb493 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java @@ -33,17 +33,15 @@ public class SearchSimpleQuery { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT QUERY PHRASES HERE: String queryPhrase = "Hoodie"; String visitorId = UUID.randomUUID().toString(); @@ -58,11 +56,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java b/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java index 784dbb5b..13777406 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java @@ -35,17 +35,15 @@ public class SearchWithBoostSpec { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT CONDITIONS HERE: String searchQuery = "Tee"; String condition = "(colorFamilies: ANY(\"Blue\"))"; @@ -69,11 +67,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java b/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java index 93000fde..d7131586 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java @@ -30,17 +30,15 @@ public class SearchWithFacetSpec { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT CONDITIONS HERE: String searchQuery = "Tee"; String facetKeyParam = "colorFamilies"; @@ -60,11 +58,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java b/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java index 27e2656b..44354872 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java @@ -33,17 +33,15 @@ public class SearchWithFiltering { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT FILTER EXPRESSIONS HERE: String filter = "(colorFamilies: ANY(\"Black\"))"; String queryPhrase = "Tee"; @@ -61,11 +59,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java b/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java index c71346cb..e3ca6270 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java @@ -33,17 +33,15 @@ public class SearchWithOrdering { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT ORDER BY EXPRESSION HERE: String order = "price desc"; String queryPhrase = "Hoodie"; @@ -60,11 +58,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java b/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java index f93c6f6d..0dae5016 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java @@ -34,17 +34,15 @@ public class SearchWithPagination { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT PAGINATION PARAMETERS HERE: int pageSize = 6; String queryPhrase = "Hoodie"; @@ -63,6 +61,10 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponseFirstPage = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponseFirstPage); @@ -70,8 +72,6 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName // PASTE CALL WITH NEXT PAGE TOKEN HERE: // PASTE CALL WITH OFFSET HERE: - - return searchResponseFirstPage; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java b/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java index d45ceda7..e98b5516 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java @@ -36,17 +36,15 @@ public class SearchWithQueryExpansionSpec { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT QUERY EXPANSION CONDITION HERE: Condition condition = Condition.AUTO; int pageSize = 10; @@ -66,11 +64,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java b/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java index 7e9176b3..a5e8f118 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchSimpleQuery.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchSimpleQueryTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java index f291dbf3..aa93dd83 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchWithBoostSpec.getSearchResponse; +import static search.SearchWithBoostSpec.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithBoostSpecTest { private ByteArrayOutputStream bout; private PrintStream originalPrintStream; @@ -43,7 +46,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java index 1f17de86..9b7a8c4d 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchWithFacetSpec.getSearchResponse; +import static search.SearchWithFacetSpec.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithFacetSpecTest { private ByteArrayOutputStream bout; private PrintStream originalPrintStream; @@ -43,7 +46,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java index 2a5b16d3..25550258 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithFiltering.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithFilteringTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java index b9051771..7a597745 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithOrdering.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithOrderingTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java index a40a350d..1c9de653 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithPagination.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithPaginationTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java index eca657c7..492ca775 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithQueryExpansionSpec.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithQueryExpansionSpecTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test