Skip to content

Commit

Permalink
Merge pull request #11 from flyingbag/master
Browse files Browse the repository at this point in the history
SDK-35 #comment Added Java SDK support for "get all meta" feature
  • Loading branch information
Jasonpeng committed Nov 13, 2015
2 parents 6381942 + 0e1961d commit 79508b0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@ for (ImageResult imageResult : imageResults) {
Map<String, String> metadata = imageResult.getMetadata();
// read your metadata here
}
```

To retrieve all metadata of your image results, specify ```get_all_fl``` parameter and set it to ```true```:

```java
SearchParams params = new SearchParams("vintage_wingtips");
params.setGetAllFl(true);
PagedSearchResult searchResult = client.search(params);
List<ImageResult> imageResults = searchResult.getResult();
for (ImageResult imageResult : imageResults) {
Map<String, String> metadata = imageResult.getMetadata();
// read your metadata here
}
```

> Only metadata of type string, int, and float can be retrieved from ViSearch. Metadata of type text is not available for retrieval.
Expand Down
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.2.3</version>
<version>1.2.4</version>
<packaging>jar</packaging>
<url>https://github.com/visenze/visearch-sdk-java</url>
<description>ViSearch Java SDK</description>
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/visenze/visearch/BaseSearchParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BaseSearchParams<P extends BaseSearchParams<P>> {
static final private List<String> DEFAULT_FL = Lists.newArrayList();
static final private Boolean DEFAULT_QINFO = false;
static final private Map<String, String> DEFAULT_CUSTOM = new HashMap<String, String>();
static final private Boolean DEFAULT_GET_ALL_FL = false;

protected Optional<Integer> page = Optional.absent();
protected Optional<Integer> limit = Optional.absent();
Expand All @@ -33,6 +34,7 @@ public class BaseSearchParams<P extends BaseSearchParams<P>> {
protected Optional<Float> scoreMax = Optional.absent();
protected Optional<Map<String, String>> fq = Optional.absent();
protected Optional<List<String>> fl = Optional.absent();
protected Optional<Boolean> getAllFl = Optional.absent();
protected Optional<Boolean> qInfo = Optional.absent();
protected Optional<Map<String, String>> custom = Optional.absent();

Expand Down Expand Up @@ -90,6 +92,12 @@ public P setFl(List<String> fl) {
return (P) this;
}

@SuppressWarnings("unchecked")
public P setGetAllFl(Boolean getAllFl) {
this.getAllFl = Optional.fromNullable(getAllFl);
return (P) this;
}

@SuppressWarnings("unchecked")
public P setQInfo(Boolean qInfo) {
this.qInfo = Optional.fromNullable(qInfo);
Expand Down Expand Up @@ -138,6 +146,11 @@ public List<String> getFl() {
return fl.or(DEFAULT_FL);
}

public Boolean isGetAllFl()
{
return getAllFl.or(DEFAULT_GET_ALL_FL);
}

public Boolean isQInfo() {
return qInfo.or(DEFAULT_QINFO);
}
Expand Down Expand Up @@ -182,6 +195,10 @@ public Multimap<String, String> toMap() {
map.put("fl", fl);
}

if (isGetAllFl()) {
map.put("get_all_fl", "true");
}

if (isQInfo()) {
map.put("qinfo", "true");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void testSearchParamsFull() {
.setScoreMax(0.75f)
.setFq(fq)
.setFl(Lists.newArrayList("field_x", "field_y"))
.setGetAllFl(true)
.setQInfo(true)
.setCustom(custom);
searchOperations.search(searchParams);
Expand All @@ -109,6 +110,7 @@ public void testSearchParamsFull() {
expectedParams.put("fq", "field_b:value_b");
expectedParams.put("fl", "field_x");
expectedParams.put("fl", "field_y");
expectedParams.put("get_all_fl", "true");
expectedParams.put("qinfo", "true");
expectedParams.put("custom_key", "custom_value");
verify(mockClient).get("/search", expectedParams);
Expand Down

0 comments on commit 79508b0

Please sign in to comment.