When you search for images, you can specify filter conditions to enable the system to return only the images that meet the conditions. For example, you can specify filter conditions to enable the system to return only the images for which the owner ID is 1000 or the company name is Alibaba.
Requirements on instance versions
Only the instances that are created after March 27, 2018 support the filter feature. The instances that are created on or before March 27, 2018 can support this feature only after the instances are upgraded. To upgrade the instances, submit a ticket.
Specify fields
When you add an image, you must specify the IntAttr and StrAttr fields. The IntAttr field represents an integer field, and the StrAttr field represents a string field. You can search for images based on these two fields. Image Search allows you to add images by using multiple methods. The following examples describe how to specify the IntAttr and StrAttr fields for different methods.
- If you add images by performing batch operations, specify the IntAttr and StrAttr
fields by referring to the following example. For more information, see Perform batch operations.
{"OperationType": "ADD","ProductId": "1000","CategoryId": 0,"IntAttr": 123,"StrAttr": "value1","CustomContent": "k1:v1,k2:v2,k3:v3","PicName": "girl_cloth1.jpg"}
- If you add images by using SDK V1.0.3 or later, call the setIntAttr and setStrAttr
methods in the AddItemRequest object. For more information, see Add.
- If you add images in the Image Search console, perform the following operation:
In the Image Search console, specify the Integer Attribute and String Attribute parameters on the Add Sample Image tab.
Search for images by specifying filter conditions
- The int_attr field supports the following operators:
- >
- >=
- <
- <=
- =
- The str_attr field supports the following operators:
- =
- !=
Examples:
int_attr>=100
str_attr!="value1"
int_attr=1000 AND str_attr="value1"
- If you search for images by calling an API operation, specify filter conditions by
setting the filter parameter in the API operation. For more information, see Request parameters.
- If you search for images by using an SDK, specify filter conditions by calling the
setFilterClause method in the SearchItemRequest object. For more information, see
SearchImageByPic.
- If you search for images in the Image Search console, perform the following operation:
On the Search by Image tab, specify the Filter Condition parameter based on the preceding examples.