From 9eea449e7d0a6f7a6873ab9969a044932a0a179d Mon Sep 17 00:00:00 2001 From: Hung Date: Wed, 27 Jul 2022 16:46:49 +0800 Subject: [PATCH 1/3] update request response --- visearch-android/build.gradle | 4 +-- .../visearch/android/IdSearchParams.java | 28 +++++++++++++++++++ .../android/ProductSearchByIdParams.java | 22 +++++++++++++++ .../visenze/visearch/android/ResultList.java | 10 +++++++ .../android/api/SearchOperations.java | 2 +- .../visearch/android/model/ImageResult.java | 11 ++++++++ .../visearch/android/model/Product.java | 11 ++++++++ .../android/model/ProductResponse.java | 11 ++++++++ .../visearch/android/model/ResponseData.java | 13 +++++++++ 9 files changed, 109 insertions(+), 3 deletions(-) diff --git a/visearch-android/build.gradle b/visearch-android/build.gradle index 109b18a..3244fc0 100644 --- a/visearch-android/build.gradle +++ b/visearch-android/build.gradle @@ -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 diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/IdSearchParams.java b/visearch-android/src/main/java/com/visenze/visearch/android/IdSearchParams.java index f108526..3bd3200 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/IdSearchParams.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/IdSearchParams.java @@ -18,6 +18,10 @@ public class IdSearchParams extends SearchParams { private String dedupBy; + private Boolean showPinnedImNames; + + private Boolean showExcludedImNames; + public IdSearchParams() { super(); } @@ -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 > toMap() { Map > map = super.toMap(); @@ -93,6 +113,14 @@ public Map > 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; } diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/ProductSearchByIdParams.java b/visearch-android/src/main/java/com/visenze/visearch/android/ProductSearchByIdParams.java index 18d6737..1a7171d 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/ProductSearchByIdParams.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/ProductSearchByIdParams.java @@ -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; } @@ -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; } diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/ResultList.java b/visearch-android/src/main/java/com/visenze/visearch/android/ResultList.java index 3b44318..fdb85c6 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/ResultList.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/ResultList.java @@ -53,6 +53,8 @@ public class ResultList { // recommendation related private String algorithm; + private List excludedImNames; + public ResultList() { imageResult = new ArrayList(); queryInfo = new HashMap(); @@ -231,4 +233,12 @@ public String getAlgorithm() { public void setAlgorithm(String algorithm) { this.algorithm = algorithm; } + + public List getExcludedImNames() { + return excludedImNames; + } + + public void setExcludedImNames(List excludedImNames) { + this.excludedImNames = excludedImNames; + } } diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/api/SearchOperations.java b/visearch-android/src/main/java/com/visenze/visearch/android/api/SearchOperations.java index 1a908cf..f7c7170 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/api/SearchOperations.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/api/SearchOperations.java @@ -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 diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/model/ImageResult.java b/visearch-android/src/main/java/com/visenze/visearch/android/model/ImageResult.java index c489a11..d3e1b8f 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/model/ImageResult.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/model/ImageResult.java @@ -23,6 +23,9 @@ public class ImageResult { @SerializedName("score") private Float score; + @SerializedName("pinned") + private Boolean pinned; + @SerializedName("value_map") private Map fieldList; @@ -134,4 +137,12 @@ public void setAlternatives(List alternatives) { public void setTags(Map tags) { this.tags = tags; } + + public Boolean getPinned() { + return pinned; + } + + public void setPinned(Boolean pinned) { + this.pinned = pinned; + } } diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/model/Product.java b/visearch-android/src/main/java/com/visenze/visearch/android/model/Product.java index 9dc2aeb..578bb41 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/model/Product.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/model/Product.java @@ -23,6 +23,9 @@ public class Product { @SerializedName("score") private Float score; + @SerializedName("pinned") + private Boolean pinned; + @SerializedName("image_s3_url") private String s3Url; @@ -145,4 +148,12 @@ public List getAlternatives() { public void setAlternatives(List alternatives) { this.alternatives = alternatives; } + + public Boolean getPinned() { + return pinned; + } + + public void setPinned(Boolean pinned) { + this.pinned = pinned; + } } diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/model/ProductResponse.java b/visearch-android/src/main/java/com/visenze/visearch/android/model/ProductResponse.java index 63ba970..922f389 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/model/ProductResponse.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/model/ProductResponse.java @@ -55,6 +55,9 @@ public class ProductResponse { @SerializedName("experiment") private Experiment experiment; + @SerializedName("excluded_pids") + private List excludedPids; + public String getStatus() { return status; } @@ -190,4 +193,12 @@ public void setExperiment(Experiment experiment) { public boolean experimentNoRecommendation() { return (experiment != null && experiment.isExpNoRecommendation()); } + + public List getExcludedPids() { + return excludedPids; + } + + public void setExcludedPids(List excludedPids) { + this.excludedPids = excludedPids; + } } diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/model/ResponseData.java b/visearch-android/src/main/java/com/visenze/visearch/android/model/ResponseData.java index ee70c36..f2db254 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/model/ResponseData.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/model/ResponseData.java @@ -74,6 +74,9 @@ public class ResponseData { @SerializedName("algorithm") private String algorithm; + @SerializedName("excluded_im_names") + private List excludedImNames; + public void setStatus(String status) { this.status = status; } @@ -142,6 +145,10 @@ public void setAlgorithm(String algorithm) { this.algorithm = algorithm; } + public void setExcludedImNames(List excludedImNames) { + this.excludedImNames = excludedImNames; + } + public List getFacets() { return facets; } @@ -190,6 +197,10 @@ public String getAlgorithm() { return algorithm; } + public List getExcludedImNames() { + return excludedImNames; + } + public ResultList getResultList() { ResultList resultList = new ResultList(); if(error != null && error.length > 0) { @@ -214,6 +225,8 @@ public ResultList getResultList() { resultList.setReqid(reqId); resultList.setFacets(facets); + resultList.setExcludedImNames(excludedImNames); + return resultList; } From 797e06c14c6379232cf497a4c833ac80ccaa4d2d Mon Sep 17 00:00:00 2001 From: Hung Date: Wed, 27 Jul 2022 16:47:48 +0800 Subject: [PATCH 2/3] update README version --- doc/ProductSearch.md | 2 +- doc/ViSearch.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ProductSearch.md b/doc/ProductSearch.md index 73f89db..9be7c60 100644 --- a/doc/ProductSearch.md +++ b/doc/ProductSearch.md @@ -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 diff --git a/doc/ViSearch.md b/doc/ViSearch.md index a31c592..4272ff9 100644 --- a/doc/ViSearch.md +++ b/doc/ViSearch.md @@ -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 From cec87d9a02de89eee69a9fd2c96108fc529028d2 Mon Sep 17 00:00:00 2001 From: Hung Date: Wed, 27 Jul 2022 17:09:34 +0800 Subject: [PATCH 3/3] update tests --- .../visearch/android/ProductSearchTest.java | 63 +++++++++++++++++++ .../visearch/android/ViSearchTest.java | 50 +++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/visearch-android/src/test/java/com/visenze/visearch/android/ProductSearchTest.java b/visearch-android/src/test/java/com/visenze/visearch/android/ProductSearchTest.java index 0937946..7d1a2a9 100644 --- a/visearch-android/src/test/java/com/visenze/visearch/android/ProductSearchTest.java +++ b/visearch-android/src/test/java/com/visenze/visearch/android/ProductSearchTest.java @@ -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)); + } + }); + + } } diff --git a/visearch-android/src/test/java/com/visenze/visearch/android/ViSearchTest.java b/visearch-android/src/test/java/com/visenze/visearch/android/ViSearchTest.java index d887c9e..b0c7159 100644 --- a/visearch-android/src/test/java/com/visenze/visearch/android/ViSearchTest.java +++ b/visearch-android/src/test/java/com/visenze/visearch/android/ViSearchTest.java @@ -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)); + } } \ No newline at end of file