Skip to content

Commit

Permalink
add new api
Browse files Browse the repository at this point in the history
  • Loading branch information
thehung111 committed Jul 8, 2024
1 parent 3f6f430 commit 48f7c7f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 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.14.3</version>
<version>1.14.4</version>
<packaging>jar</packaging>
<url>https://github.com/visenze/visearch-sdk-java</url>
<description>ViSearch Java SDK</description>
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/visenze/visearch/BrowseLinkedGalleryParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.visenze.visearch;

import com.google.common.collect.Multimap;

/**
* Created by Hung on 8/7/24.
*/
public class BrowseLinkedGalleryParams extends BaseSearchParams<BrowseLinkedGalleryParams> {
private String strategyId;

public BrowseLinkedGalleryParams(String strategyId) {
this.strategyId = strategyId;
}

@Override
public Multimap<String, String> toMap() {
Multimap<String, String> map = super.toMap();

if (strategyId != null) {
map.put("strategy_id", strategyId.toString());
}

return map;
}

public String getStrategyId() {
return strategyId;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/visenze/visearch/ViSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ public PagedSearchResult search(SearchParams searchParams) {
return searchOperations.search(searchParams);
}

@Override
public PagedSearchResult browseLinkedGalleryImages(BrowseLinkedGalleryParams params) {
return searchOperations.browseLinkedGalleryImages(params);
}

/**
* Search for similar images from the ViSearch App given image and/or text query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface SearchOperations {

PagedSearchResult recommendation(RecommendSearchParams searchParams);

PagedSearchResult browseLinkedGalleryImages(BrowseLinkedGalleryParams params);

PagedSearchResult colorSearch(ColorSearchParams colorSearchParams);

PagedSearchResult uploadSearch(UploadSearchParams uploadSearchParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class SearchOperationsImpl extends BaseViSearchOperations implements Sear
private static final String ENDPOINT_MULTI_SEARCH_AUTOCOMPLETE = "/multisearch/autocomplete";

private static final String ENDPOINT_SEARCH = "/search";
private static final String ENDPOINT_BROWSE_LINKED_GALLERY = "/linked/gallery/browse";
private static final String ENDPOINT_RECOMMENDATION = "/recommendations";
private static final String ENDPOINT_COLOR_SEARCH = "/colorsearch";
private static final String ENDPOINT_SIMILAR_PRODUCTS_SEARCH = "/similarproducts";
Expand All @@ -48,6 +49,16 @@ public PagedSearchResult search(SearchParams searchParams) {
}
}

@Override
public PagedSearchResult browseLinkedGalleryImages(BrowseLinkedGalleryParams params) {
try {
ViSearchHttpResponse response = viSearchHttpClient.get(ENDPOINT_BROWSE_LINKED_GALLERY, params.toMap());
return getPagedResult(response);
} catch (InternalViSearchException e) {
return new PagedSearchResult(e.getMessage(), e.getCause(), e.getServerRawResponse());
}
}

@Override
public PagedSearchResult recommendation(RecommendSearchParams recommendSearchParams) {
try {
Expand Down Expand Up @@ -126,7 +137,7 @@ public PagedSearchResult similarProductsSearch(UploadSearchParams uploadSearchPa
/**
* Extract feature string (encoded in base 64) given an image file or url.
*
* @param uploadSearchParams the upload search parameters, must contain a image file or a url
* @param uploadSearchParams the upload search parameters, must contain an image file or url
* @return the feature response string result
*/
@Override
Expand Down Expand Up @@ -367,7 +378,7 @@ private PagedSearchResult getPagedResult(ViSearchHttpResponse httpResponse) {
result.setSetInfoList(setInfoList);
}

// For similarproducts search, try to cover it's result into discoversearch result.
// For similarproducts search, try to convert its result into discoversearch result.
JsonNode groupResult = node.get(ViSearchHttpConstants.GROUP_RESULT);
if (groupResult != null && groupResult instanceof ArrayNode) {
List<ProductType> productTypes = result.getProductTypes();
Expand Down

0 comments on commit 48f7c7f

Please sign in to comment.