Skip to content

Commit

Permalink
Merge pull request #90 from visenze/feature/pin_exclude
Browse files Browse the repository at this point in the history
[API-8236] Add pin/excluded product request/response support
  • Loading branch information
thehung111 authored Jul 27, 2022
2 parents 8a2fd8d + cec87d9 commit c532a52
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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.1
> Current stable version: 2.2.2
> Minimum Android SDK Version: API 9, Android 2.3
Expand Down
2 changes: 1 addition & 1 deletion 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.0
>Current stable version: 2.2.2
>Minimum Android SDK Version: API 9, Android 2.3
Expand Down
4 changes: 2 additions & 2 deletions visearch-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {

def versionMajor = 2
def versionMinor = 2
def versionPatch = 1
version = '2.2.1'
def versionPatch = 2
version = '2.2.2'

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

private String dedupBy;

private Boolean showPinnedImNames;

private Boolean showExcludedImNames;

public IdSearchParams() {
super();
}
Expand Down Expand Up @@ -76,6 +80,22 @@ public void setDedupBy(String dedupBy) {
this.dedupBy = dedupBy;
}

public Boolean getShowPinnedImNames() {
return showPinnedImNames;
}

public void setShowPinnedImNames(Boolean showPinnedImNames) {
this.showPinnedImNames = showPinnedImNames;
}

public Boolean getShowExcludedImNames() {
return showExcludedImNames;
}

public void setShowExcludedImNames(Boolean showExcludedImNames) {
this.showExcludedImNames = showExcludedImNames;
}

@Override
public Map<String, List<String> > toMap() {
Map<String, List<String> > map = super.toMap();
Expand All @@ -93,6 +113,14 @@ public Map<String, List<String> > toMap() {
putStringInMap(map, "alt_limit", String.valueOf(altLimit));
}

if (showPinnedImNames != null) {
putStringInMap(map, "show_pinned_im_names", showPinnedImNames.toString());
}

if (showExcludedImNames != null) {
putStringInMap(map, "show_excluded_im_names", showExcludedImNames.toString());
}

return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public class ProductSearchByIdParams extends BaseProductSearchParams {
@SerializedName("strategy_id")
private Integer strategyId;

@SerializedName("show_pinned_pids")
private Boolean showPinnedPids;

@SerializedName("show_excluded_pids")
private Boolean showExcludedPids;

public String getProductId() {
return productId;
}
Expand All @@ -38,6 +44,22 @@ public void setStrategyId(Integer strategyId) {
this.strategyId = strategyId;
}

public Boolean getShowPinnedPids() {
return showPinnedPids;
}

public void setShowPinnedPids(Boolean showPinnedPids) {
this.showPinnedPids = showPinnedPids;
}

public Boolean getShowExcludedPids() {
return showExcludedPids;
}

public void setShowExcludedPids(Boolean showExcludedPids) {
this.showExcludedPids = showExcludedPids;
}

public ProductSearchByIdParams(String productId) {
this.productId = productId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class ResultList {
// recommendation related
private String algorithm;

private List<String> excludedImNames;

public ResultList() {
imageResult = new ArrayList<ImageResult>();
queryInfo = new HashMap<String, String>();
Expand Down Expand Up @@ -231,4 +233,12 @@ public String getAlgorithm() {
public void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
}

public List<String> getExcludedImNames() {
return excludedImNames;
}

public void setExcludedImNames(List<String> excludedImNames) {
this.excludedImNames = excludedImNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface SearchOperations {
public void search(IdSearchParams idSearchParams, final ViSearch.ResultListener resultListener);

/**
* Recommendation (GET /recommendation)
* Recommendation (GET /recommendations)
* Get list of recommended images against the image collection using an existing image in the collection
*
* @param idSearchParams the index search parameter setting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class ImageResult {
@SerializedName("score")
private Float score;

@SerializedName("pinned")
private Boolean pinned;

@SerializedName("value_map")
private Map<String, String> fieldList;

Expand Down Expand Up @@ -134,4 +137,12 @@ public void setAlternatives(List<ImageResult> alternatives) {
public void setTags(Map<String, Object> tags) {
this.tags = tags;
}

public Boolean getPinned() {
return pinned;
}

public void setPinned(Boolean pinned) {
this.pinned = pinned;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class Product {
@SerializedName("score")
private Float score;

@SerializedName("pinned")
private Boolean pinned;

@SerializedName("image_s3_url")
private String s3Url;

Expand Down Expand Up @@ -145,4 +148,12 @@ public List<Product> getAlternatives() {
public void setAlternatives(List<Product> alternatives) {
this.alternatives = alternatives;
}

public Boolean getPinned() {
return pinned;
}

public void setPinned(Boolean pinned) {
this.pinned = pinned;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class ProductResponse {
@SerializedName("experiment")
private Experiment experiment;

@SerializedName("excluded_pids")
private List<String> excludedPids;

public String getStatus() {
return status;
}
Expand Down Expand Up @@ -190,4 +193,12 @@ public void setExperiment(Experiment experiment) {
public boolean experimentNoRecommendation() {
return (experiment != null && experiment.isExpNoRecommendation());
}

public List<String> getExcludedPids() {
return excludedPids;
}

public void setExcludedPids(List<String> excludedPids) {
this.excludedPids = excludedPids;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public class ResponseData {
@SerializedName("algorithm")
private String algorithm;

@SerializedName("excluded_im_names")
private List<String> excludedImNames;

public void setStatus(String status) {
this.status = status;
}
Expand Down Expand Up @@ -142,6 +145,10 @@ public void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
}

public void setExcludedImNames(List<String> excludedImNames) {
this.excludedImNames = excludedImNames;
}

public List<Facet> getFacets() {
return facets;
}
Expand Down Expand Up @@ -190,6 +197,10 @@ public String getAlgorithm() {
return algorithm;
}

public List<String> getExcludedImNames() {
return excludedImNames;
}

public ResultList getResultList() {
ResultList resultList = new ResultList();
if(error != null && error.length > 0) {
Expand All @@ -214,6 +225,8 @@ public ResultList getResultList() {
resultList.setReqid(reqId);

resultList.setFacets(facets);
resultList.setExcludedImNames(excludedImNames);

return resultList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,67 @@ public void onSearchResult(ProductResponse response, ErrorData error) {

}

@Test
public void testPinExcludeResponse() {
String json =
"{\n" +
" \"reqid\": \"01806a667776c6f8a31c28105fd99e\",\n" +
" \"status\": \"OK\",\n" +
" \"method\": \"product/recommendations\",\n" +
" \"page\": 1,\n" +
" \"limit\": 10,\n" +
" \"total\": 1,\n" +
" \"product_types\": [],\n" +
" \"result\": [\n" +
" {\n" +
" \"product_id\": \"top-name-11\",\n" +
" \"main_image_url\": \"https://localhost/top-name-11.jpg\",\n" +
" \"data\": {\n" +
" \"title\": \"top-name-001\"\n" +
" },\n" +
" \"tags\": {\n" +
" \"category\": \"top\"\n" +
" },\n" +
" \"pinned\": \"true\",\n" +
" \"alternatives\": [\n" +
" {\n" +
" \"product_id\": \"top-name-22\",\n" +
" \"main_image_url\": \"https://localhost/top-name-22.jpg\",\n" +
" \"data\": {\n" +
" \"title\": \"top-name-002\"\n" +
" }\n" +
" },\n" +
" {\n" +
" \"product_id\": \"top-name-33\",\n" +
" \"main_image_url\": \"https://localhost/top-name-33.jpg\",\n" +
" \"data\": {\n" +
" \"title\": \"top-name-003\"\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
" ],\n" +
" \"strategy\": {\n" +
" \"id\": 3,\n" +
" \"name\": \"test\",\n" +
" \"algorithm\": \"STL\"\n" +
" },\n" +
" \"excluded_pids\" : [\"p1\", \"p2\"],\n" +
" \"alt_limit\": 5\n" +
"}";

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

assertTrue(response.getProducts().get(0).getPinned());
assertEquals(2, response.getExcludedPids().size());
assertEquals("p1" , response.getExcludedPids().get(0));
assertEquals("p2" , response.getExcludedPids().get(1));
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,54 @@ public void testRecommendationResponse() throws Exception{
assertEquals("top-name-003", imageResult.getAlternatives().get(1).getMetaData().getOrDefault("title", null));

}

@Test
public void testRecommendationResponseWithExcludedPids() throws Exception{
String responseBody = "{\n" +
" \"status\": \"OK\",\n" +
" \"method\": \"recommendations\",\n" +
" \"algorithm\": \"STL\",\n" +
" \"error\": [],\n" +
" \"page\": 1,\n" +
" \"limit\": 3,\n" +
" \"total\": 1,\n" +
" \"result\": [\n" +
" {\n" +
" \"im_name\": \"image_F01\",\n" +
" \"score\": 0.6613727807998657,\n" +
" \"alternatives\": [\n" +
" {\n" +
" \"im_name\": \"image_bag_3\",\n" +
" \"score\": 0.6613727807998657\n" +
" }\n" +
" ],\n" +
" \"pinned\" : \"true\",\n" +
" \"tags\": {\n" +
" \"query_product_id\": \"image_bag_5\",\n" +
" \"category\": \"bag\",\n" +
" \"query_image_url\": \"https://test.jpg\"\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"excluded_im_names\" : [\"im1\", \"im2\"],\n" +
" \"reqid\": \"1317439821672620035\"\n" +
"}";;

ResponseData response = gson.fromJson(responseBody, ResponseData.class);
ResultList resultList = response.getResultList();

assertEquals("STL", resultList.getAlgorithm());
assertTrue(1 == resultList.getImageList().size());

ImageResult imageResult = resultList.getImageList().get(0);
assertEquals("image_F01", imageResult.getImageName());

assertEquals(1, imageResult.getAlternatives().size());
assertEquals("image_bag_3", imageResult.getAlternatives().get(0).getImageName());
assertTrue(imageResult.getPinned());

assertEquals(2, resultList.getExcludedImNames().size());
assertEquals("im1" , resultList.getExcludedImNames().get(0));
assertEquals("im2" , resultList.getExcludedImNames().get(1));
}
}

0 comments on commit c532a52

Please sign in to comment.