This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
Product search rebased #196
Merged
beccasaurus
merged 27 commits into
googleapis:master
from
nirupa-kumar:product-search-rebased
Sep 18, 2018
Merged
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
069c6ac
Update samples to use ^0.21.0 for v1p3beta1
8b06377
Add Product Search samples to create/list/delete products
6115ecd
Linting for Product Search create/list/delete
c6685e8
Product Search – Get Product sample
1cf8929
Move Product Search tests into productSearch/
b21f4b8
Refactor | reuse helper variable in Product Search – List Products te…
0e51f2c
Product Search samples – Product Set create/get/list/delete
1b4bc74
updates region tags to standard
alixhami d18b783
Added sample for createReferenceImage
happyhuman c16aec5
Added getReferenceImage sample (needs fixing)
happyhuman f106e6d
Implemented listReferenceImages, deleteReferenceImage, and getReferen…
happyhuman bb09b8f
Added the sample for addProductToProductSet
happyhuman 4c71d56
Added samples for listProductInProductSet and removeProductFromProduc…
happyhuman 916b8d3
Added inline parameter comments
happyhuman 213eb74
Added sample for updateProductLabels
happyhuman a6cf3c2
Merge branch 'product-search-samples' of https://github.com/googleapi…
nirupa-kumar 29e381e
Updates Product search samples - import product set & similar product…
nirupa-kumar a77793e
Fixing linting issues
nirupa-kumar a95a4fd
Fixing linting issues
nirupa-kumar 60063c8
Fixing linting issues
nirupa-kumar 89d96e1
Fixing linting issues
nirupa-kumar cbeaa46
Fixing linting issues
nirupa-kumar 51eafa4
Fixing linting issues
nirupa-kumar df71265
Fixing review comments
nirupa-kumar 2aef582
Fixing review comments
nirupa-kumar 50ed679
Fixing review comments
nirupa-kumar 464c2aa
Fixing review comments
nirupa-kumar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright 2018, 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
// [START vision_product_search_import_product_images] | ||
function importProductSets(projectId, location, gcsUri) { | ||
// Imports the Google Cloud client library | ||
const vision = require('@google-cloud/vision').v1p3beta1; | ||
// Creates a client | ||
var client = new vision.ProductSearchClient(); | ||
|
||
/** | ||
* TODO(developer): Uncomment the following line before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud project Id'; | ||
// const location = 'A compute region name'; | ||
// const gcsUri = 'Google Cloud Storage path of the input image''; | ||
|
||
// A resource that represents Google Cloud Platform location. | ||
const projectLocation = client.locationPath(projectId, location); | ||
|
||
// Set the input configuration along with Google Cloud Storage URI | ||
const inputConfig = { | ||
gcsSource: { | ||
csvFileUri: gcsUri, | ||
}, | ||
}; | ||
|
||
// Import the product sets from the input URI. | ||
client | ||
.importProductSets({parent: projectLocation, inputConfig: inputConfig}) | ||
.then(responses => { | ||
var response = responses[0]; | ||
var operation = responses[1]; | ||
console.log('Processing operation name: ', operation.name); | ||
|
||
// synchronous check of operation status | ||
return response.promise(); | ||
}) | ||
.then(responses => { | ||
console.log('Processing done.'); | ||
console.log('Results of the processing:'); | ||
|
||
for (var i in responses[0].statuses) { | ||
console.log( | ||
'Status of processing ', | ||
i, | ||
'of the csv:', | ||
responses[0].statuses[i] | ||
); | ||
|
||
// Check the status of reference image | ||
if (responses[0].statuses[i].code === 0) { | ||
console.log(responses[0].referenceImages[i]); | ||
} else { | ||
console.log('No reference image.'); | ||
} | ||
} | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
// [END vision_product_search_import_product_images] | ||
} | ||
// [END vision_product_search_import_product_set] | ||
|
||
require(`yargs`) // eslint-disable-line | ||
.demand(1) | ||
.command( | ||
`importProductSets <projectId> <location> <gcsUri>`, | ||
`Import a Product Set`, | ||
{}, | ||
opts => importProductSets(opts.projectId, opts.location, opts.gcsUri) | ||
) | ||
.example(`node $0 COMMAND ARG`) | ||
.wrap(120) | ||
.recommendCommands() | ||
.epilogue(`For more information, see https://cloud.google.com/vision/docs`) | ||
.help() | ||
.strict().argv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/** | ||
* Copyright 2018, 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function addProductToProductSet(projectId, location, productId, productSetId) { | ||
// [START vision_product_search_add_product_to_product_set] | ||
|
||
const vision = require('@google-cloud/vision').v1p3beta1; | ||
|
||
var client = new vision.ProductSearchClient(); | ||
|
||
/** | ||
* TODO(developer): Uncomment the following line before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud project Id'; | ||
// const location = 'A compute region name'; | ||
// const productId = 'Id of the product'; | ||
// const productSetId = 'Id of the product set'; | ||
|
||
var productSetPath = client.productSetPath(projectId, location, productSetId); | ||
|
||
var productPath = client.productPath(projectId, location, productId); | ||
|
||
var request = { | ||
name: productSetPath, | ||
product: productPath, | ||
}; | ||
|
||
client | ||
.addProductToProductSet(request) | ||
.then(() => { | ||
console.log(`Product added to product set.`); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
// [END vision_product_search_add_product_to_product_set] | ||
} | ||
|
||
function listProductsInProductSet(projectId, location, productSetId) { | ||
// [START vision_product_search_list_products_in_product_set] | ||
|
||
const vision = require('@google-cloud/vision').v1p3beta1; | ||
|
||
var client = new vision.ProductSearchClient(); | ||
|
||
/** | ||
* TODO(developer): Uncomment the following line before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud project Id'; | ||
// const location = 'A compute region name'; | ||
// const productSetId = 'Id of the product set'; | ||
|
||
var productSetPath = client.productSetPath(projectId, location, productSetId); | ||
|
||
var request = { | ||
name: productSetPath, | ||
}; | ||
|
||
client.listProductsInProductSet(request).then(results => { | ||
const products = results[0]; | ||
products.forEach(product => { | ||
console.log(`Product name: ${product.name}`); | ||
console.log(`Product display name: ${product.displayName}`); | ||
}); | ||
}); | ||
// [END vision_product_search_list_products_in_product_set] | ||
} | ||
|
||
function removeProductFromProductSet( | ||
projectId, | ||
location, | ||
productId, | ||
productSetId | ||
) { | ||
// [START vision_product_search_remove_product_from_product_set] | ||
|
||
const vision = require('@google-cloud/vision').v1p3beta1; | ||
|
||
var client = new vision.ProductSearchClient(); | ||
|
||
/** | ||
* TODO(developer): Uncomment the following line before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud project Id'; | ||
// const location = 'A compute region name'; | ||
// const productId = 'Id of the product'; | ||
// const productSetId = 'Id of the product set'; | ||
|
||
var productSetPath = client.productSetPath(projectId, location, productSetId); | ||
|
||
var productPath = client.productPath(projectId, location, productId); | ||
|
||
var request = { | ||
name: productSetPath, | ||
product: productPath, | ||
}; | ||
|
||
client | ||
.removeProductFromProductSet(request) | ||
.then(() => { | ||
console.log(`Product removed from product set.`); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
// [END vision_product_search_remove_product_from_product_set] | ||
} | ||
|
||
require(`yargs`) // eslint-disable-line | ||
.demand(1) | ||
.command( | ||
`addProductToProductSet <projectId> <location> <productId> <productSetId>`, | ||
`Add a product to product set`, | ||
{}, | ||
opts => | ||
addProductToProductSet( | ||
opts.projectId, | ||
opts.location, | ||
opts.productId, | ||
opts.productSetId | ||
) | ||
) | ||
.command( | ||
`listProductsInProductSet <projectId> <location> <productSetId>`, | ||
`List all products in a product set`, | ||
{}, | ||
opts => | ||
listProductsInProductSet(opts.projectId, opts.location, opts.productSetId) | ||
) | ||
.command( | ||
`removeProductFromProductSet <projectId> <location> <productId> <productSetId>`, | ||
`Remove a products from a product set`, | ||
{}, | ||
opts => | ||
removeProductFromProductSet( | ||
opts.projectId, | ||
opts.location, | ||
opts.productId, | ||
opts.productSetId | ||
) | ||
) | ||
.example(`node $0 COMMAND ARG`) | ||
.wrap(120) | ||
.recommendCommands() | ||
.epilogue(`For more information, see https://cloud.google.com/vision/docs`) | ||
.help() | ||
.strict().argv; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.