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 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 the 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 filter images based on these two fields. Image Search allows you to add images by using multiple methods. In the following examples, the settings of the two fields are provided for different methods.

  • If you add images by performing batch operations, the settings of the two fields are provided in the following example:
    {"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 1.0.3 or later:

    You can specify the setIntAttr and setStrAttr fields in the AddItemRequest function.

  • If you add images in the Image Search console:
    On the Add Sample Image tab in the Image Search console, you can specify the Integer Attribute and String Attribute parameters.Filter by conditions - console

Filter by fields

When you search for images, you can specify filter conditions to enable the system to return the images that meet the conditions. The int_attr field supports the following operators: >, >=, <, <=, and =. The str_attr field supports the following operators: = and !=. Multiple filter conditions are joined by AND or OR. The following example is provided:
int_attr>=100
str_attr! ="value1"
int_attr=1000 AND str_attr="value1"
  • If you search for images by calling API operations:

    You can set the filter parameter in the API operation to the value that is specified in the preceding conditions.

  • If you search for images by using SDKs:

    You can specify the filter conditions by calling the setFilterClause function in SearchItemRequest.

  • If you search for images in the Image Search console:
    On the Search by Image tab, you can specify the Filter Condition parameter based on the preceding example.Filter by conditions - console settings