From 02d26e0cdabb1ed3ccef3aabac97cb7788153d1d Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 30 Jan 2025 20:38:23 -0800 Subject: [PATCH 1/3] basic python search example for docs --- retail/doc-samples/search.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 retail/doc-samples/search.py diff --git a/retail/doc-samples/search.py b/retail/doc-samples/search.py new file mode 100644 index 000000000000..a59b0ccd632a --- /dev/null +++ b/retail/doc-samples/search.py @@ -0,0 +1,32 @@ +from google.cloud import retail_v2 + +def search_products(project_id, catalog_id, placement_id, branch, visitor_id, query): + client = retail_v2.SearchServiceClient() + + placement_name = retail_v2.SearchServiceClient.placement_path( + project_id, location='global', catalog=catalog_id, placement=placement_id + ) + + search_request = retail_v2.SearchRequest( + placement=placement_name, + branch=branch, + visitor_id=visitor_id, + query=query, + page_size=10 + ) + + response = client.search(search_request) + + print(f"Search response: {response}") + + return response + +# Example usage +project_id = 'YOUR_PROJECT_ID' +catalog_id = 'YOUR_CATALOG_ID' +placement_id = 'YOUR_PLACEMENT_ID' +branch = 'YOUR_BRANCH_NAME' +visitor_id = 'YOUR_VISITOR_ID' +query = 'YOUR_QUERY' + +search_products(project_id, catalog_id, placement_id, branch, visitor_id, query) From 00f09cba16c7fc1664e2655eaf54420b6228f751 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 30 Jan 2025 20:38:23 -0800 Subject: [PATCH 2/3] basic python search example for docs --- retail/doc-samples/search.py | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 retail/doc-samples/search.py diff --git a/retail/doc-samples/search.py b/retail/doc-samples/search.py new file mode 100644 index 000000000000..3ca77137ca33 --- /dev/null +++ b/retail/doc-samples/search.py @@ -0,0 +1,46 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +from google.cloud import retail_v2 + +def search_products(project_id, catalog_id, placement_id, branch, visitor_id, query): + client = retail_v2.SearchServiceClient() + + placement_name = retail_v2.SearchServiceClient.placement_path( + project_id, location='global', catalog=catalog_id, placement=placement_id + ) + + search_request = retail_v2.SearchRequest( + placement=placement_name, + branch=branch, + visitor_id=visitor_id, + query=query, + page_size=10 + ) + + response = client.search(search_request) + + print(f"Search response: {response}") + + return response + +# Example usage +project_id = 'YOUR_PROJECT_ID' +catalog_id = 'YOUR_CATALOG_ID' +placement_id = 'YOUR_PLACEMENT_ID' +branch = 'YOUR_BRANCH_NAME' +visitor_id = 'YOUR_VISITOR_ID' +query = 'YOUR_QUERY' + +search_products(project_id, catalog_id, placement_id, branch, visitor_id, query) From 58ee105ed3342ea1ef8b952dbc5c4eb370d9b552 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 3 Feb 2025 10:14:20 -0800 Subject: [PATCH 3/3] Update retail/doc-samples/search.py license notice Co-authored-by: Holt Skinner <13262395+holtskinner@users.noreply.github.com> --- retail/doc-samples/search.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/retail/doc-samples/search.py b/retail/doc-samples/search.py index 3ca77137ca33..3449ae87ab46 100644 --- a/retail/doc-samples/search.py +++ b/retail/doc-samples/search.py @@ -1,16 +1,16 @@ -// Copyright 2025 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from google.cloud import retail_v2