Skip to content

Commit

Permalink
Merge pull request #97 from visenze/feature/default_params
Browse files Browse the repository at this point in the history
[API-9195] don't send parameters default value if not proviided
  • Loading branch information
thehung111 authored May 9, 2023
2 parents a03b364 + 59166aa commit a009dc9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 79 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.visenze</groupId>
<artifactId>visearch-java-sdk</artifactId>
<name>ViSearch Java SDK</name>
<version>1.13.3</version>
<version>1.13.4</version>
<packaging>jar</packaging>
<url>https://github.com/visenze/visearch-sdk-java</url>
<description>ViSearch Java SDK</description>
Expand Down
75 changes: 17 additions & 58 deletions src/main/java/com/visenze/visearch/BaseSearchParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Map;

import static com.visenze.common.util.MultimapUtil.putIfPresent;
import static com.visenze.visearch.internal.constant.ViSearchHttpConstants.*;

/**
Expand Down Expand Up @@ -346,54 +347,23 @@ public void setVaSid(String vaSid) {
public Multimap<String, String> toMap() {
Multimap<String, String> map = LinkedHashMultimap.create();

if (getPage() != null) {
map.put(PAGE, getPage().toString());
}
if (getLimit() != null) {
map.put(LIMIT, getLimit().toString());
}

if (groupBy.isPresent()){
map.put(GROUP_BY, getGroupBy() );
}

if (groupLimit.isPresent()){
map.put(GROUP_LIMIT, getGroupLimit().toString() );
}
putIfPresent(map, page, PAGE);
putIfPresent(map, limit, LIMIT);
putIfPresent(map, groupBy, GROUP_BY);
putIfPresent(map, groupLimit, GROUP_LIMIT);

if (!getFacets().isEmpty()) {
map.put(FACETS, Joiner.on(COMMA).join(getFacets()));
}
if (facetsLimit.isPresent()) {
map.put(FACETS_LIMIT, facetsLimit.get().toString());
}
if (facetsShowCount.isPresent()) {
map.put(FACETS_SHOW_COUNT, facetsShowCount.get().toString());
}
if (isScore()) {
map.put(SCORE, TRUE);
} else {
map.put(SCORE, FALSE);
}

if (getScoreMin() != null) {
map.put(SCORE_MIN, getScoreMin().toString());
}
if (getScoreMax() != null) {
map.put(SCORE_MAX, getScoreMax().toString());
}
putIfPresent(map, facetsLimit, FACETS_LIMIT);
putIfPresent(map, facetsShowCount, FACETS_SHOW_COUNT);

if (sortBy.isPresent()) {
map.put(SORT_BY, getSortBy() );
}

if (sortGroupBy.isPresent()) {
map.put(SORT_GROUP_BY, getSortGroupBy());
}

if (sortGroupStrategy.isPresent()) {
map.put(SORT_GROUP_STRATEGY, getSortGroupStrategy());
}
putIfPresent(map, score, SCORE);
putIfPresent(map, scoreMin, SCORE_MIN);
putIfPresent(map, scoreMax, SCORE_MAX);
putIfPresent(map, sortBy, SORT_BY);
putIfPresent(map, sortGroupBy, SORT_GROUP_BY);
putIfPresent(map, sortGroupStrategy, SORT_GROUP_STRATEGY);

addAnalyticsParams(map);

Expand All @@ -414,21 +384,10 @@ public Multimap<String, String> toMap() {
map.put(FL, filter);
}

if (isGetAllFl()) {
map.put(GET_ALL_FL, TRUE);
}

if (isQInfo()) {
map.put(QINFO, TRUE);
}

if (isDedup()) {
map.put(DEDUP, TRUE);
}

if (getDedupThreshold() != null) {
map.put(DEDUP_SCORE_THRESHOLD, getDedupThreshold().toString());
}
putIfPresent(map, getAllFl, GET_ALL_FL);
putIfPresent(map, qInfo, QINFO);
putIfPresent(map, dedup, DEDUP);
putIfPresent(map, dedupThreshold, DEDUP_SCORE_THRESHOLD);

for (DiversityQuery diversityQuery : getDiversityQueries()) {
map.put(DIVERSITY, diversityQuery.toParamValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void testSearchParamsBasic() {
assertEquals(null, pagedSearchResult.getRawResponseMessage());
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "test_im");
expectedParams.put("score", "false");
verify(mockClient).get("/search", expectedParams);
}

Expand All @@ -84,7 +83,6 @@ public void testSearchParamsFacet() {
expectedParams.put("facets", "brand");
expectedParams.put("facets_limit", "10");
expectedParams.put("facets_show_count", "true");
expectedParams.put("score", "false");
verify(mockClient).get("/search", expectedParams);
}

Expand All @@ -98,7 +96,8 @@ public void testSearchParamsFacetOnNumber() {
SearchParams searchParams = new SearchParams("test_im")
.setFacets(Lists.newArrayList("brand"))
.setFacetsLimit(10)
.setFacetsShowCount(true);
.setFacetsShowCount(true)
.setScore(false);
PagedSearchResult searchResult = searchOperations.search(searchParams);
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "test_im");
Expand Down Expand Up @@ -381,7 +380,6 @@ public void testColorSearchParams() {
searchOperations.colorSearch(colorSearchParams);
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("color", "123ABC");
expectedParams.put("score", "false");
verify(mockClient).get("/colorsearch", expectedParams);
}

Expand Down Expand Up @@ -420,7 +418,6 @@ public void testUploadSearchParamsURL() {
searchOperations.uploadSearch(uploadSearchParams);
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_url", "http://www.example.com/test_im.jpeg");
expectedParams.put("score", "false");
verify(mockClient).post("/uploadsearch", expectedParams);
}

Expand All @@ -438,7 +435,6 @@ public void testUploadSearchParamsURLWithDetection() {
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_url", "http://www.example.com/test_im.jpeg");
expectedParams.put("detection", "dress");
expectedParams.put("score", "false");
verify(mockClient).post("/uploadsearch", expectedParams);
assertEquals(3, uploadSearchResult.getProductTypes().size());
assertEquals(6, uploadSearchResult.getProductTypesList().size());
Expand Down Expand Up @@ -498,7 +494,6 @@ public void testDiscoverSearchParamsURL() {
PagedSearchResult uploadSearchResult = searchOperations.discoverSearch(uploadSearchParams);
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_url", "http://www.example.com/test_im.jpeg");
expectedParams.put("score", "false");
verify(mockClient).post("/discoversearch", expectedParams);
assertEquals(3, uploadSearchResult.getObjects().size());
assertEquals(6, uploadSearchResult.getObjectTypesList().size());
Expand Down Expand Up @@ -905,7 +900,6 @@ public void testDiscoverSearchMerged() {
PagedSearchResult uploadSearchResult = searchOperations.discoverSearch(uploadSearchParams);
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_url", "http://www.example.com/test_im.jpeg");
expectedParams.put("score", "false");

verify(mockClient).post("/discoversearch", expectedParams);

Expand Down Expand Up @@ -957,7 +951,6 @@ public void testUploadSearchParamsURLUploadSearch() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_url", "http://www.example.com/test_im.jpeg");
expectedParams.put("score", "false");
expectedParams.put("sort_by", "price:asc");

verify(mockClient).post("/uploadsearch", expectedParams);
Expand Down Expand Up @@ -990,7 +983,6 @@ public void testUploadSearchParamsURLUploadSearchWithRerankScore() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_url", "http://www.example.com/test_im.jpeg");
expectedParams.put("score", "false");
expectedParams.put("sort_by", "price:asc");

verify(mockClient).post("/uploadsearch", expectedParams);
Expand Down Expand Up @@ -1023,7 +1015,6 @@ public void testSearchGroupedResponseSortBy() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "test_im");
expectedParams.put("score", "false");
expectedParams.put("sort_group_by", "price:asc");
expectedParams.put("sort_group_strategy", "first");

Expand Down Expand Up @@ -1071,7 +1062,6 @@ public void testSearchParamsBasicS3Url() {
assertEquals(null, pagedSearchResult.getCause());
Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "test_im1");
expectedParams.put("score", "false");
verify(mockClient).get("/search", expectedParams);

}
Expand Down Expand Up @@ -1209,7 +1199,6 @@ public void testSearchParamsVsFl() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", testImName);
expectedParams.put("score", "false");
expectedParams.put("vs_fl", sysField);
expectedParams.put("vs_config", "a:b");

Expand All @@ -1227,7 +1216,6 @@ public void testMatchSearch() {
expectedParams.put("im_name", "im_name");
expectedParams.put("object_limit", "-1");
expectedParams.put("result_limit", "10");
expectedParams.put("score", "false");
given(mockClient.get(eq("/match"), eq(expectedParams))).willReturn(response);

SearchOperations searchOperations = new SearchOperationsImpl(mockClient, objectMapper);
Expand Down Expand Up @@ -1272,7 +1260,6 @@ public void testMatchSearchGroupBy() {
expectedParams.put("im_name", "im_name");
expectedParams.put("object_limit", "-1");
expectedParams.put("result_limit", "10");
expectedParams.put("score", "false");
given(mockClient.get(eq("/match"), eq(expectedParams))).willReturn(response);

SearchOperations searchOperations = new SearchOperationsImpl(mockClient, objectMapper);
Expand Down Expand Up @@ -1319,7 +1306,6 @@ public void testRecommendationResponseParsing() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "im_name");
expectedParams.put("score", "false");
given(mockClient.post(eq("/recommendations"), eq(expectedParams))).willReturn(response);

SearchOperations searchOperations = new SearchOperationsImpl(mockClient, objectMapper);
Expand Down Expand Up @@ -1381,7 +1367,6 @@ public void testRecommendationResponsePinExcludedParsing() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "im_name");
expectedParams.put("score", "false");
expectedParams.put("show_pinned_im_names", "true");
expectedParams.put("show_excluded_im_names", "true");
expectedParams.put("use_set_based_ctl", "false");
Expand Down Expand Up @@ -1426,7 +1411,6 @@ public void testSBRRecommendationFallbackResponseParsing() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "im_name");
expectedParams.put("score", "false");
given(mockClient.post(eq("/recommendations"), eq(expectedParams))).willReturn(response);

SearchOperations searchOperations = new SearchOperationsImpl(mockClient, objectMapper);
Expand Down Expand Up @@ -1490,7 +1474,6 @@ public void testParseCtlSetBasedResponse() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "im_name1");
expectedParams.put("score", "false");
given(mockClient.post(eq("/recommendations"), eq(expectedParams))).willReturn(response);

SearchOperations searchOperations = new SearchOperationsImpl(mockClient, objectMapper);
Expand Down Expand Up @@ -1580,7 +1563,6 @@ public void testParseBestImagesResponse() {

Multimap<String, String> expectedParams = HashMultimap.create();
expectedParams.put("im_name", "im_name3");
expectedParams.put("score", "false");
expectedParams.put("show_best_product_images", "true");
given(mockClient.post(eq("/recommendations"), eq(expectedParams))).willReturn(response);

Expand Down

0 comments on commit a009dc9

Please sign in to comment.