How can I specify max_results parameter if I am using Python script for Google Product Search API?

506 Views Asked by At

While searching a product_set using command line, we can set a parameter features.max Results to limit the number of items returned in the response.

Field-specific considerations:

features.maxResults - The maximum number of results to be returned.

But how can I pass this parameter while running the python script provided here?

Also, does this parameter affect the response time?

1

There are 1 best solutions below

1
ewertonvsilva On BEST ANSWER

The documentation is really not very well written, but I found that you just have to add the parameter max_results=<max> inside the method product_search as following:

response = image_annotator_client.product_search(
        image, image_context=image_context,max_results=2)

To confirm that it works, I've added the an debug line inside the file on the google library /usr/local/lib/python3.7/dist-packages/google/cloud/vision_helpers/decorators.py

And when I run the code, I get the printout of the request made to the api, and as you can see, the parameter is correctly defined:

# python3 search.py 

Result:

#BEGIN DEBUG:
{'image': source {
  image_uri: "gs://<bucket>/short-blue.jpeg"
}
, 'features': [{'type_': <Type.PRODUCT_SEARCH: 12>, 'max_results': 2}], 'image_context': product_search_params {
  product_set: "projects/<project>/locations/us-west1/productSets/product-set-name"
  product_categories: "apparel-v2"
  filter: "color:blue"
}
}
#END DEBUG:

Product set index time: 
None
Search results: