Skip to content

Commit ff46b25

Browse files
sborisenkoxtetiana-karasovat-karasovagcf-owl-bot[bot]kweinmeister
authored
docs(samples): Refactoring search package (#415)
* Update README * the bash scripts are added * Update README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update user_environment_setup.sh * Update user_import_data_to_catalog.sh * Update README.md * Refactoring search package. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: tetiana-karasova <[email protected]> Co-authored-by: t-karasova <[email protected]> Co-authored-by: t-karasova <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Karl Weinmeister <[email protected]>
1 parent 01cd2a0 commit ff46b25

14 files changed

+77
-56
lines changed

retail/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@
3333
public class SearchSimpleQuery {
3434

3535
public static void main(String[] args) throws IOException {
36-
// TODO(developer): Replace these variables before running the sample.
3736
String projectId = ServiceOptions.getDefaultProjectId();
3837
String defaultCatalogName =
3938
String.format("projects/%s/locations/global/catalogs/default_catalog", projectId);
4039
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search";
4140

42-
getSearchResponse(defaultSearchPlacementName);
41+
searchResponse(defaultSearchPlacementName);
4342
}
4443

45-
public static SearchResponse getSearchResponse(String defaultSearchPlacementName)
46-
throws IOException {
44+
public static void searchResponse(String defaultSearchPlacementName) throws IOException {
4745
// TRY DIFFERENT QUERY PHRASES HERE:
4846
String queryPhrase = "Hoodie";
4947
String visitorId = UUID.randomUUID().toString();
@@ -58,11 +56,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
5856
.build();
5957
System.out.println("Search request: " + searchRequest);
6058

59+
// Initialize client that will be used to send requests. This client only
60+
// needs to be created once, and can be reused for multiple requests. After
61+
// completing all of your requests, call the "close" method on the client to
62+
// safely clean up any remaining background resources.
6163
try (SearchServiceClient client = SearchServiceClient.create()) {
6264
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
6365
System.out.println("Search response: " + searchResponse);
64-
65-
return searchResponse;
6666
}
6767
}
6868
}

retail/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@
3535
public class SearchWithBoostSpec {
3636

3737
public static void main(String[] args) throws IOException {
38-
// TODO(developer): Replace these variables before running the sample.
3938
String projectId = ServiceOptions.getDefaultProjectId();
4039
String defaultCatalogName =
4140
String.format("projects/%s/locations/global/catalogs/default_catalog", projectId);
4241
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search";
4342

44-
getSearchResponse(defaultSearchPlacementName);
43+
searchResponse(defaultSearchPlacementName);
4544
}
4645

47-
public static SearchResponse getSearchResponse(String defaultSearchPlacementName)
48-
throws IOException {
46+
public static void searchResponse(String defaultSearchPlacementName) throws IOException {
4947
// TRY DIFFERENT CONDITIONS HERE:
5048
String searchQuery = "Tee";
5149
String condition = "(colorFamilies: ANY(\"Blue\"))";
@@ -69,11 +67,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
6967
.build();
7068
System.out.println("Search request: " + searchRequest);
7169

70+
// Initialize client that will be used to send requests. This client only
71+
// needs to be created once, and can be reused for multiple requests. After
72+
// completing all of your requests, call the "close" method on the client to
73+
// safely clean up any remaining background resources.
7274
try (SearchServiceClient client = SearchServiceClient.create()) {
7375
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
7476
System.out.println("Search response: " + searchResponse);
75-
76-
return searchResponse;
7777
}
7878
}
7979
}

retail/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@
3030
public class SearchWithFacetSpec {
3131

3232
public static void main(String[] args) throws IOException {
33-
// TODO(developer): Replace these variables before running the sample.
3433
String projectId = ServiceOptions.getDefaultProjectId();
3534
String defaultCatalogName =
3635
String.format("projects/%s/locations/global/catalogs/default_catalog", projectId);
3736
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search";
3837

39-
getSearchResponse(defaultSearchPlacementName);
38+
searchResponse(defaultSearchPlacementName);
4039
}
4140

42-
public static SearchResponse getSearchResponse(String defaultSearchPlacementName)
43-
throws IOException {
41+
public static void searchResponse(String defaultSearchPlacementName) throws IOException {
4442
// TRY DIFFERENT CONDITIONS HERE:
4543
String searchQuery = "Tee";
4644
String facetKeyParam = "colorFamilies";
@@ -60,11 +58,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
6058
.build();
6159
System.out.println("Search request: " + searchRequest);
6260

61+
// Initialize client that will be used to send requests. This client only
62+
// needs to be created once, and can be reused for multiple requests. After
63+
// completing all of your requests, call the "close" method on the client to
64+
// safely clean up any remaining background resources.
6365
try (SearchServiceClient client = SearchServiceClient.create()) {
6466
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
6567
System.out.println("Search response: " + searchResponse);
66-
67-
return searchResponse;
6868
}
6969
}
7070
}

retail/interactive-tutorials/src/main/java/search/SearchWithFiltering.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@
3333
public class SearchWithFiltering {
3434

3535
public static void main(String[] args) throws IOException {
36-
// TODO(developer): Replace these variables before running the sample.
3736
String projectId = ServiceOptions.getDefaultProjectId();
3837
String defaultCatalogName =
3938
String.format("projects/%s/locations/global/catalogs/default_catalog", projectId);
4039
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search";
4140

42-
getSearchResponse(defaultSearchPlacementName);
41+
searchResponse(defaultSearchPlacementName);
4342
}
4443

45-
public static SearchResponse getSearchResponse(String defaultSearchPlacementName)
46-
throws IOException {
44+
public static void searchResponse(String defaultSearchPlacementName) throws IOException {
4745
// TRY DIFFERENT FILTER EXPRESSIONS HERE:
4846
String filter = "(colorFamilies: ANY(\"Black\"))";
4947
String queryPhrase = "Tee";
@@ -61,11 +59,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
6159

6260
System.out.println("Search request: " + searchRequest);
6361

62+
// Initialize client that will be used to send requests. This client only
63+
// needs to be created once, and can be reused for multiple requests. After
64+
// completing all of your requests, call the "close" method on the client to
65+
// safely clean up any remaining background resources.
6466
try (SearchServiceClient client = SearchServiceClient.create()) {
6567
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
6668
System.out.println("Search response: " + searchResponse);
67-
68-
return searchResponse;
6969
}
7070
}
7171
}

retail/interactive-tutorials/src/main/java/search/SearchWithOrdering.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@
3333
public class SearchWithOrdering {
3434

3535
public static void main(String[] args) throws IOException {
36-
// TODO(developer): Replace these variables before running the sample.
3736
String projectId = ServiceOptions.getDefaultProjectId();
3837
String defaultCatalogName =
3938
String.format("projects/%s/locations/global/catalogs/default_catalog", projectId);
4039
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search";
4140

42-
getSearchResponse(defaultSearchPlacementName);
41+
searchResponse(defaultSearchPlacementName);
4342
}
4443

45-
public static SearchResponse getSearchResponse(String defaultSearchPlacementName)
46-
throws IOException {
44+
public static void searchResponse(String defaultSearchPlacementName) throws IOException {
4745
// TRY DIFFERENT ORDER BY EXPRESSION HERE:
4846
String order = "price desc";
4947
String queryPhrase = "Hoodie";
@@ -60,11 +58,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
6058
.build();
6159
System.out.println("Search request: " + searchRequest);
6260

61+
// Initialize client that will be used to send requests. This client only
62+
// needs to be created once, and can be reused for multiple requests. After
63+
// completing all of your requests, call the "close" method on the client to
64+
// safely clean up any remaining background resources.
6365
try (SearchServiceClient client = SearchServiceClient.create()) {
6466
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
6567
System.out.println("Search response: " + searchResponse);
66-
67-
return searchResponse;
6868
}
6969
}
7070
}

retail/interactive-tutorials/src/main/java/search/SearchWithPagination.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@
3434
public class SearchWithPagination {
3535

3636
public static void main(String[] args) throws IOException {
37-
// TODO(developer): Replace these variables before running the sample.
3837
String projectId = ServiceOptions.getDefaultProjectId();
3938
String defaultCatalogName =
4039
String.format("projects/%s/locations/global/catalogs/default_catalog", projectId);
4140
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search";
4241

43-
getSearchResponse(defaultSearchPlacementName);
42+
searchResponse(defaultSearchPlacementName);
4443
}
4544

46-
public static SearchResponse getSearchResponse(String defaultSearchPlacementName)
47-
throws IOException {
45+
public static void searchResponse(String defaultSearchPlacementName) throws IOException {
4846
// TRY DIFFERENT PAGINATION PARAMETERS HERE:
4947
int pageSize = 6;
5048
String queryPhrase = "Hoodie";
@@ -63,15 +61,17 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
6361
.build();
6462
System.out.println("Search request: " + searchRequest);
6563

64+
// Initialize client that will be used to send requests. This client only
65+
// needs to be created once, and can be reused for multiple requests. After
66+
// completing all of your requests, call the "close" method on the client to
67+
// safely clean up any remaining background resources.
6668
try (SearchServiceClient client = SearchServiceClient.create()) {
6769
SearchResponse searchResponseFirstPage = client.search(searchRequest).getPage().getResponse();
6870
System.out.println("Search response: " + searchResponseFirstPage);
6971

7072
// PASTE CALL WITH NEXT PAGE TOKEN HERE:
7173

7274
// PASTE CALL WITH OFFSET HERE:
73-
74-
return searchResponseFirstPage;
7575
}
7676
}
7777
}

retail/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@
3636
public class SearchWithQueryExpansionSpec {
3737

3838
public static void main(String[] args) throws IOException {
39-
// TODO(developer): Replace these variables before running the sample.
4039
String projectId = ServiceOptions.getDefaultProjectId();
4140
String defaultCatalogName =
4241
String.format("projects/%s/locations/global/catalogs/default_catalog", projectId);
4342
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search";
4443

45-
getSearchResponse(defaultSearchPlacementName);
44+
searchResponse(defaultSearchPlacementName);
4645
}
4746

48-
public static SearchResponse getSearchResponse(String defaultSearchPlacementName)
49-
throws IOException {
47+
public static void searchResponse(String defaultSearchPlacementName) throws IOException {
5048
// TRY DIFFERENT QUERY EXPANSION CONDITION HERE:
5149
Condition condition = Condition.AUTO;
5250
int pageSize = 10;
@@ -66,11 +64,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
6664
.build();
6765
System.out.println("Search request: " + searchRequest);
6866

67+
// Initialize client that will be used to send requests. This client only
68+
// needs to be created once, and can be reused for multiple requests. After
69+
// completing all of your requests, call the "close" method on the client to
70+
// safely clean up any remaining background resources.
6971
try (SearchServiceClient client = SearchServiceClient.create()) {
7072
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
7173
System.out.println("Search response: " + searchResponse);
72-
73-
return searchResponse;
7474
}
7575
}
7676
}

retail/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package search;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20-
import static search.SearchSimpleQuery.getSearchResponse;
20+
import static search.SearchSimpleQuery.searchResponse;
2121

2222
import com.google.cloud.ServiceOptions;
2323
import java.io.ByteArrayOutputStream;
@@ -27,7 +27,10 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.JUnit4;
3032

33+
@RunWith(JUnit4.class)
3134
public class SearchSimpleQueryTest {
3235

3336
private ByteArrayOutputStream bout;
@@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException
4447
originalPrintStream = System.out;
4548
System.setOut(out);
4649

47-
getSearchResponse(defaultSearchPlacementName);
50+
searchResponse(defaultSearchPlacementName);
4851
}
4952

5053
@Test

retail/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package search;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20-
import static search.SearchWithBoostSpec.getSearchResponse;
20+
import static search.SearchWithBoostSpec.searchResponse;
2121

2222
import com.google.cloud.ServiceOptions;
2323
import java.io.ByteArrayOutputStream;
@@ -27,7 +27,10 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.JUnit4;
3032

33+
@RunWith(JUnit4.class)
3134
public class SearchWithBoostSpecTest {
3235
private ByteArrayOutputStream bout;
3336
private PrintStream originalPrintStream;
@@ -43,7 +46,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException
4346
originalPrintStream = System.out;
4447
System.setOut(out);
4548

46-
getSearchResponse(defaultSearchPlacementName);
49+
searchResponse(defaultSearchPlacementName);
4750
}
4851

4952
@Test

retail/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package search;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20-
import static search.SearchWithFacetSpec.getSearchResponse;
20+
import static search.SearchWithFacetSpec.searchResponse;
2121

2222
import com.google.cloud.ServiceOptions;
2323
import java.io.ByteArrayOutputStream;
@@ -27,7 +27,10 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.JUnit4;
3032

33+
@RunWith(JUnit4.class)
3134
public class SearchWithFacetSpecTest {
3235
private ByteArrayOutputStream bout;
3336
private PrintStream originalPrintStream;
@@ -43,7 +46,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException
4346
originalPrintStream = System.out;
4447
System.setOut(out);
4548

46-
getSearchResponse(defaultSearchPlacementName);
49+
searchResponse(defaultSearchPlacementName);
4750
}
4851

4952
@Test

retail/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package search;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20-
import static search.SearchSimpleQuery.getSearchResponse;
20+
import static search.SearchWithFiltering.searchResponse;
2121

2222
import com.google.cloud.ServiceOptions;
2323
import java.io.ByteArrayOutputStream;
@@ -27,7 +27,10 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.JUnit4;
3032

33+
@RunWith(JUnit4.class)
3134
public class SearchWithFilteringTest {
3235

3336
private ByteArrayOutputStream bout;
@@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException
4447
originalPrintStream = System.out;
4548
System.setOut(out);
4649

47-
getSearchResponse(defaultSearchPlacementName);
50+
searchResponse(defaultSearchPlacementName);
4851
}
4952

5053
@Test

0 commit comments

Comments
 (0)