Skip to content

Commit

Permalink
Merge pull request #97 from visenze/feature/best_image
Browse files Browse the repository at this point in the history
[API-8981] Best images selection
  • Loading branch information
thehung111 authored Mar 7, 2023
2 parents 562ab35 + a3bece4 commit cb843e6
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 10 deletions.
7 changes: 4 additions & 3 deletions doc/ProductSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ With the release of ViSenze's Catalog system, ViSearch Android SDK will now incl
- Aggregate search results on a product level instead of image level
- Consistent data type in API response with Catalog’s schema

> Current stable version: 2.2.6
> Current stable version: 2.3.0
> Minimum Android SDK Version: API 9, Android 2.3
Expand Down Expand Up @@ -61,10 +61,11 @@ allprojects {
}
```

include the dependency in your project using gradle:
include the dependency in your project using gradle. Please change the version to latest.

```gradle
implementation 'com.github.visenze:visenze-tracking-android:0.2.2'
implementation 'com.github.visenze:visearch-sdk-android:2.2.6'
implementation 'com.github.visenze:visearch-sdk-android:2.3.0'
```

### 1.3 Add User Permissions
Expand Down
7 changes: 4 additions & 3 deletions doc/ViSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ViSearch is an API that provides accurate, reliable and scalable image search. V

The ViSearch Android SDK is an open source software to provide easy integration of ViSearch Search API with your Android mobile applications. It provides three search methods based on the ViSearch Search API - pre-indexed search, color search and upload search. For source code and references, please visit the [Github Repository](https://github.com/visenze/visearch-sdk-android).

>Current stable version: 2.2.6
>Current stable version: 2.3.0
>Minimum Android SDK Version: API 9, Android 2.3
Expand Down Expand Up @@ -77,10 +77,11 @@ allprojects {
}
```

include the dependency in your project using gradle:
include the dependency in your project using gradle. Please change the version to latest.

```gradle
implementation 'com.github.visenze:visenze-tracking-android:0.2.2'
implementation 'com.github.visenze:visearch-sdk-android:2.2.6'
implementation 'com.github.visenze:visearch-sdk-android:2.3.0'
```

### 1.3 Add User Permissions
Expand Down
6 changes: 3 additions & 3 deletions visearch-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ plugins {
}

def versionMajor = 2
def versionMinor = 2
def versionPatch = 6
version = '2.2.6'
def versionMinor = 3
def versionPatch = 0
version = '2.3.0'

android {
compileSdkVersion 29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class IdSearchParams extends SearchParams {

private Integer setLimit;
private Boolean useSetBasedCtl;
private Boolean showBestProductImages;

public IdSearchParams() {
super();
Expand Down Expand Up @@ -148,6 +149,10 @@ public Map<String, List<String> > toMap() {
putStringInMap(map, "use_set_based_ctl", useSetBasedCtl.toString());
}

if (showBestProductImages != null) {
putStringInMap(map, "show_best_product_images", showBestProductImages.toString());
}

return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class ProductSearchByIdParams extends BaseProductSearchParams {
@SerializedName("use_set_based_ctl")
private Boolean useSetBasedCtl;

@SerializedName("show_best_product_images")
private Boolean showBestProductImages;

public String getProductId() {
return productId;
}
Expand Down Expand Up @@ -82,6 +85,14 @@ public void setUseSetBasedCtl(Boolean useSetBasedCtl) {
this.useSetBasedCtl = useSetBasedCtl;
}

public Boolean getShowBestProductImages() {
return showBestProductImages;
}

public void setShowBestProductImages(Boolean showBestProductImages) {
this.showBestProductImages = showBestProductImages;
}

public ProductSearchByIdParams(String productId) {
this.productId = productId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.visenze.visearch.android.model;

import java.io.Serializable;

import com.google.gson.annotations.SerializedName;

public class BestImage implements Serializable {

@SerializedName("type")
private String type;

@SerializedName("url")
private String url;

@SerializedName("index")
private String index;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getIndex() {
return index;
}

public void setIndex(String index) {
this.index = index;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class ImageResult {
@SerializedName("tags")
private Map<String, Object> tags;

@SerializedName("best_images")
private List<BestImage> bestImages;

public ImageResult() {
this.fieldList = new HashMap<String, String>();
}
Expand Down Expand Up @@ -145,4 +148,12 @@ public Boolean getPinned() {
public void setPinned(Boolean pinned) {
this.pinned = pinned;
}

public List<BestImage> getBestImages() {
return bestImages;
}

public void setBestImages(List<BestImage> bestImages) {
this.bestImages = bestImages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class Product {
@SerializedName("alternatives")
private List<Product> alternatives;

@SerializedName("best_images")
private List<BestImage> bestImages;

public String getProductId() {
return productId;
}
Expand Down Expand Up @@ -156,4 +159,12 @@ public Boolean getPinned() {
public void setPinned(Boolean pinned) {
this.pinned = pinned;
}

public List<BestImage> getBestImages() {
return bestImages;
}

public void setBestImages(List<BestImage> bestImages) {
this.bestImages = bestImages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.visenze.visearch.android.model.BestImage;
import com.visenze.visearch.android.model.ErrorData;
import com.visenze.visearch.android.model.Experiment;
import com.visenze.visearch.android.model.ImageResult;
Expand Down Expand Up @@ -34,7 +35,7 @@
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP, manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class ProductSearchTest {
ProductSearchService searchService = new ProductSearchService("https://visearch.visenze.com", "123", 456, "visearch-test");
ProductSearchService searchService = new ProductSearchService("https://search.visenze.com", "123", 456, "visearch-test");
Gson gson = new GsonBuilder()
.setLenient()
.create();
Expand Down Expand Up @@ -691,4 +692,84 @@ public void onSearchResult(ProductResponse response, ErrorData error) {
});

}

@Test
public void testBestImagesResponse() {
String json =
"{\n" +
" \"reqid\": \"01806a667776c6f8a31c28105fd99f\",\n" +
" \"status\": \"OK\",\n" +
" \"method\": \"product/recommendations\",\n" +
" \"page\": 1,\n" +
" \"limit\": 20,\n" +
" \"total\": 200,\n" +
" \"product_types\": [],\n" +
" \"result\": [\n" +
"{\n" +
" \"product_id\": \"dress1\",\n" +
" \"main_image_url\": \"http://test.com/img1.jpg\",\n" +

" \"best_images\": [\n" +
" {\n" +
" \"type\": \"product\",\n" +
" \"url\": \"url11\",\n" +
" \"index\": \"0\"\n" +
" },\n" +
" {\n" +
" \"type\": \"outfit\",\n" +
" \"url\": \"url21\",\n" +
" \"index\": \"3\"\n" +
" }\n" +
" ],\n" +

" \"tags\": {\n" +
" \"category\": \"dress\",\n" +
" \"set_id\": \"set1\"\n" +
" },\n" +
" \"score\": 0.9\n" +
" }\n" +

" ],\n" +
"\"set_info\": [\n" +
" {\n" +
" \"set_id\": \"set1\",\n" +
" \"set_score\": 1000\n" +
" },\n" +
" {\n" +
" \"set_id\": \"set2\",\n" +
" \"set_score\": 900\n" +
" }\n" +
" ]," +
" \"strategy\": {\n" +
" \"id\": 3,\n" +
" \"name\": \"test\",\n" +
" \"algorithm\": \"CTL\"\n" +
" }\n" +
"}";

ProductResponse response = gson.fromJson(json, ProductResponse.class);
searchService.handleResponse(response, new ProductSearch.ResultListener() {
@Override
public void onSearchResult(ProductResponse response, ErrorData error) {
assertNull(error);

List<Product> result = response.getProducts();
assertEquals(1, result.size());

List<BestImage> bestImages = result.get(0).getBestImages();
assertEquals(2, bestImages.size());

BestImage b1 = bestImages.get(0);
assertEquals("0", b1.getIndex());
assertEquals("product", b1.getType());
assertEquals("url11", b1.getUrl());

BestImage b2 = bestImages.get(1);
assertEquals("3", b2.getIndex());
assertEquals("outfit", b2.getType());
assertEquals("url21", b2.getUrl());
}
});

}
}

0 comments on commit cb843e6

Please sign in to comment.