Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Product search rebased #196

Merged
merged 27 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
Jul 24, 2018
8b06377
Add Product Search samples to create/list/delete products
Jul 24, 2018
6115ecd
Linting for Product Search create/list/delete
Jul 24, 2018
c6685e8
Product Search – Get Product sample
Jul 24, 2018
1cf8929
Move Product Search tests into productSearch/
Jul 24, 2018
b21f4b8
Refactor | reuse helper variable in Product Search – List Products te…
Jul 24, 2018
0e51f2c
Product Search samples – Product Set create/get/list/delete
Jul 24, 2018
1b4bc74
updates region tags to standard
alixhami Aug 14, 2018
d18b783
Added sample for createReferenceImage
happyhuman Aug 22, 2018
c16aec5
Added getReferenceImage sample (needs fixing)
happyhuman Aug 24, 2018
f106e6d
Implemented listReferenceImages, deleteReferenceImage, and getReferen…
happyhuman Aug 27, 2018
bb09b8f
Added the sample for addProductToProductSet
happyhuman Aug 30, 2018
4c71d56
Added samples for listProductInProductSet and removeProductFromProduc…
happyhuman Aug 30, 2018
916b8d3
Added inline parameter comments
happyhuman Aug 30, 2018
213eb74
Added sample for updateProductLabels
happyhuman Aug 31, 2018
a6cf3c2
Merge branch 'product-search-samples' of https://github.com/googleapi…
nirupa-kumar Sep 11, 2018
29e381e
Updates Product search samples - import product set & similar product…
nirupa-kumar Sep 11, 2018
a77793e
Fixing linting issues
nirupa-kumar Sep 11, 2018
a95a4fd
Fixing linting issues
nirupa-kumar Sep 11, 2018
60063c8
Fixing linting issues
nirupa-kumar Sep 11, 2018
89d96e1
Fixing linting issues
nirupa-kumar Sep 11, 2018
cbeaa46
Fixing linting issues
nirupa-kumar Sep 11, 2018
51eafa4
Fixing linting issues
nirupa-kumar Sep 11, 2018
df71265
Fixing review comments
nirupa-kumar Sep 17, 2018
2aef582
Fixing review comments
nirupa-kumar Sep 17, 2018
50ed679
Fixing review comments
nirupa-kumar Sep 17, 2018
464c2aa
Fixing review comments
nirupa-kumar Sep 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions samples/productSearch/importProductSets.v1p3beta1.js
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
const 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 => {
const response = responses[0];
const 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 (let 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;
165 changes: 165 additions & 0 deletions samples/productSearch/productSearch.v1p3beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* 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;

const 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';

const productPath = client.productPath(projectId, location, productId);
const productSetPath = client.productSetPath(
projectId,
location,
productSetId
);

const 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;

const 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';
const productSetPath = client.productSetPath(
projectId,
location,
productSetId
);
const 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;

const client = new vision.ProductSearchClient();

/**
* TODO(developer): Uncomment the following line before running the sample.
*/
const productSetPath = client.productSetPath(
projectId,
location,
productSetId
);

const productPath = client.productPath(projectId, location, productId);

const 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;
Loading