Skip to content

Commit

Permalink
add autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
thehung111 committed Nov 27, 2023
1 parent 46c1201 commit 23793d3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void multisearch(ProductSearchByImageParams imageSearchParams, ResultList
productSearchService.searchByImage(imageSearchParams, listener, true);
}

public void multisearchAutocomplete(ProductSearchByImageParams imageSearchParams, AutoCompleteResultListener listener) {
addAnalyticsParams(imageSearchParams);
productSearchService.multisearchAutocomplete(imageSearchParams, listener);
}

public void recommendations(ProductSearchByIdParams visualSimilarParams, ResultListener listener) {
searchById(visualSimilarParams, listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.visenze.visearch.android.model.AutoCompleteResponse;
import com.visenze.visearch.android.model.AutoCompleteResultItem;
import com.visenze.visearch.android.model.BestImage;
import com.visenze.visearch.android.model.Box;
import com.visenze.visearch.android.model.ErrorData;
Expand Down Expand Up @@ -1014,6 +1016,55 @@ public void onSearchResult(ProductResponse response, ErrorData error) {

}

@Test
public void testAutocompleteResponse() {
String json =
"{\n" +
" \"result\": [\n" +
" {\n" +
" \"text\": \"red1\",\n" +
" \"score\": 898.0\n" +
" },\n" +
" {\n" +
" \"text\": \"red valentino\",\n" +
" \"score\": 188.0\n" +
" },\n" +
" {\n" +
" \"text\": \"oscar de la renta\",\n" +
" \"score\": 46.0\n" +
" }\n" +
" ],\n" +
" \"method\": \"multisearch/autocomplete\",\n" +
" \"status\": \"OK\",\n" +
" \"page\": 1,\n" +
" \"reqid\": \"14952330933117065212\"\n" +
"}";

AutoCompleteResponse response = gson.fromJson(json, AutoCompleteResponse.class);
searchService.handleAutoCompleteResponse(response, new ProductSearch.AutoCompleteResultListener() {
@Override
public void onResult(AutoCompleteResponse response, ErrorData error) {
assertNull(error);

assertEquals(1, response.getPage());
assertEquals("14952330933117065212", response.getReqId());

AutoCompleteResultItem item = response.getResult().get(0);
assertEquals("red1", item.getText());
assertTrue(898.0 == item.getScore());

AutoCompleteResultItem item2 = response.getResult().get(1);
assertEquals("red valentino", item2.getText());
assertTrue(188.0 == item2.getScore());

AutoCompleteResultItem item3 = response.getResult().get(2);
assertEquals("oscar de la renta", item3.getText());
assertTrue(46.0 == item3.getScore());
}
});

}

private String getBoxString(Box box) {
return box.getX1() + "," + box.getY1() + "," + box.getX2() + "," + box.getY2();
}
Expand Down

0 comments on commit 23793d3

Please sign in to comment.