Skip to content

Commit

Permalink
Merge pull request #104 from visenze/feature/multisearch
Browse files Browse the repository at this point in the history
[API-9945] Multi-search algorithm
  • Loading branch information
thehung111 authored Nov 27, 2023
2 parents 79891a6 + 23793d3 commit e4b6b16
Show file tree
Hide file tree
Showing 14 changed files with 423 additions and 50 deletions.
6 changes: 3 additions & 3 deletions visearch-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ plugins {
}

def versionMajor = 2
def versionMinor = 3
def versionPatch = 5
version = '2.3.5'
def versionMinor = 4
def versionPatch = 0
version = '2.4.0'

android {
compileSdkVersion 29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.visenze.datatracking.Tracker;
import com.visenze.datatracking.VisenzeAnalytics;
import com.visenze.datatracking.data.DataCollection;
import com.visenze.visearch.android.model.AutoCompleteResponse;
import com.visenze.visearch.android.model.ErrorData;
import com.visenze.visearch.android.model.ProductResponse;
import com.visenze.visearch.android.network.ProductSearchService;
Expand Down Expand Up @@ -39,6 +40,16 @@ public void searchById(ProductSearchByIdParams visualSimilarParams, ResultListen
productSearchService.searchById(visualSimilarParams, listener);
}

public void multisearch(ProductSearchByImageParams imageSearchParams, ResultListener listener) {
addAnalyticsParams(imageSearchParams);
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 Expand Up @@ -160,9 +171,12 @@ public ProductSearch build(Context context) {
}
}

public static interface ResultListener {
public void onSearchResult(final ProductResponse response, ErrorData error);
public interface ResultListener {
void onSearchResult(final ProductResponse response, ErrorData error);
}

public interface AutoCompleteResultListener {
void onResult(final AutoCompleteResponse response, ErrorData error);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class ProductSearchByImageParams extends BaseProductSearchParams {
// internal serialization
@SerializedName("box")
private String boxParam;

@SerializedName("q")
private String q;

public Boolean getSearchAllObjects() {
return searchAllObjects;
Expand Down Expand Up @@ -104,6 +107,14 @@ public String getBoxParam() {
return boxParam;
}

public String getQ() {
return q;
}

public void setQ(String q) {
this.q = q;
}

public ProductSearchByImageParams() {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class UploadSearchParams extends SearchParams {

private Integer resultLimit;

private String q;

public UploadSearchParams() {
super();
}
Expand Down Expand Up @@ -117,6 +119,16 @@ public UploadSearchParams setAttributes(Map<String, String> attributes) {
return this;
}

/**
*
* @param q text query
* @return this instance.
*/
public UploadSearchParams setQ(String q) {
this.q = q;
return this;
}

/**
* Get {@link Image Image} that is set to search
*
Expand Down Expand Up @@ -153,6 +165,15 @@ public String getDetection() {
return detection;
}

/**
* Get text query
*
* @return text query.
*/
public String getQ() {
return q;
}

@Override
public Map<String, List<String> > toMap() {
Map<String, List<String> > map = super.toMap();
Expand Down Expand Up @@ -203,6 +224,10 @@ public Map<String, List<String> > toMap() {
putStringInMap(map, "result_limit", resultLimit.toString());
}

if (q != null) {
putStringInMap(map,"q", q);
}

return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface SearchOperations {
* Upload Search (POST /uploadsearch)
* Searching against the image collection with an uploading image.
*
* @param uploadSearchParams the index search parameter setting
* @param uploadSearchParams request params
* @param resultListener result listener
*/
public void uploadSearch(UploadSearchParams uploadSearchParams, final ViSearch.ResultListener resultListener);
Expand All @@ -50,11 +50,19 @@ public interface SearchOperations {
* Discover Search (POST /discoversearch)
* Multiple Products Search
*
* @param uploadSearchParams the index search parameter setting
* @param uploadSearchParams request params
* @param resultListener result listener
*/
public void discoverSearch(UploadSearchParams uploadSearchParams, final ViSearch.ResultListener resultListener);

/**
* Multi Search (POST /multisearch)
* Multi-search (image and text query)
*
* @param uploadSearchParams request params (image and text query)
* @param resultListener result listener
*/
public void multiSearch(UploadSearchParams uploadSearchParams, final ViSearch.ResultListener resultListener);

public void cancelSearch(ViSearch.ResultListener resultListener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void discoverSearch(UploadSearchParams uploadSearchParams, ViSearch.Resul
searchService.uploadSearch(SearchService.DISCOVER_SEARCH, uploadSearchParams, resultListener);
}

@Override
public void multiSearch(UploadSearchParams uploadSearchParams, ViSearch.ResultListener resultListener) {
searchService.uploadSearch(SearchService.MULTI_SEARCH, uploadSearchParams, resultListener);
}

@Override
public void cancelSearch(ViSearch.ResultListener resultListener) {
resultListener.onSearchCanceled();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.visenze.visearch.android.model;

import com.google.gson.annotations.SerializedName;

import java.util.List;

public class AutoCompleteResponse {

@SerializedName("status")
private String status;

@SerializedName("method")
private String method;

@SerializedName("error")
private ErrorData error;

@SerializedName("result")
private List<AutoCompleteResultItem> result;

@SerializedName("page")
private int page;

@SerializedName("limit")
private int limit;

@SerializedName("total")
private int total;

@SerializedName("reqid")
private String reqId;

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getMethod() {
return method;
}

public void setMethod(String method) {
this.method = method;
}

public ErrorData getError() {
return error;
}

public void setError(ErrorData error) {
this.error = error;
}

public List<AutoCompleteResultItem> getResult() {
return result;
}

public void setResult(List<AutoCompleteResultItem> result) {
this.result = result;
}

public int getPage() {
return page;
}

public void setPage(int page) {
this.page = page;
}

public int getLimit() {
return limit;
}

public void setLimit(int limit) {
this.limit = limit;
}

public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public String getReqId() {
return reqId;
}

public void setReqId(String reqId) {
this.reqId = reqId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.visenze.visearch.android.model;

import com.google.gson.annotations.SerializedName;

public class AutoCompleteResultItem {

@SerializedName("text")
private String text;

@SerializedName("score")
private double score;

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public double getScore() {
return score;
}

public void setScore(double score) {
this.score = score;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ public void setMessage(String message) {
this.message = message;
}


public static ErrorData unknownError(String msg) {
ErrorData error = new ErrorData();
error.setMessage(msg);
error.setCode(-1);
return error;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.visenze.visearch.android.network;

import com.visenze.visearch.android.model.AutoCompleteResponse;
import com.visenze.visearch.android.model.ProductResponse;
import com.visenze.visearch.android.network.retry.Retry;

Expand Down Expand Up @@ -28,5 +29,21 @@ public interface APIProductService {
@POST("product/search_by_image")
Call<ProductResponse> searchByImage(@Part MultipartBody.Part image, @QueryMap RetrofitQueryMap query);

@Retry
@POST("product/multisearch")
Call<ProductResponse> multisearch(@QueryMap RetrofitQueryMap query);

@Retry
@Multipart
@POST("product/multisearch")
Call<ProductResponse> multisearch(@Part MultipartBody.Part image, @QueryMap RetrofitQueryMap query);

@Retry
@POST("product/multisearch/autocomplete")
Call<AutoCompleteResponse> multisearchAutocomplete(@QueryMap RetrofitQueryMap query);

@Retry
@Multipart
@POST("product/multisearch/autocomplete")
Call<AutoCompleteResponse> multisearchAutocomplete(@Part MultipartBody.Part image, @QueryMap RetrofitQueryMap query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ public interface APIService {
@POST("discoversearch")
Call<ResponseData> discoverSearch(@HeaderMap Map<String, String> headers, @Part MultipartBody.Part image, @QueryMap RetrofitQueryMap query);

@Retry
@GET("multisearch")
Call<ResponseData> multiSearch(@HeaderMap Map<String, String> headers, @QueryMap RetrofitQueryMap query);

@Retry
@Multipart
@POST("multisearch")
Call<ResponseData> multiSearch(@HeaderMap Map<String, String> headers, @Part MultipartBody.Part image, @QueryMap RetrofitQueryMap query);

}
Loading

0 comments on commit e4b6b16

Please sign in to comment.