Skip to content

Commit

Permalink
Update parameters for new free text search #27
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Jul 13, 2022
1 parent f16bddb commit 50dbf32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
34 changes: 17 additions & 17 deletions src/main/java/org/icatproject/icat/client/ICAT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map.Entry;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonException;
import javax.json.JsonReader;
import javax.json.JsonString;
Expand Down Expand Up @@ -593,8 +594,8 @@ String searchInvestigations(String sessionId, String user, String text, Date low
}

String searchInvestigations(String sessionId, String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, List<String> samples, String userFullName, String searchAfter, int limit, String sort, String facets)
throws IcatException {
List<ParameterForLucene> parameters, String userFullName, String searchAfter, int maxCount, String sort,
JsonArray facets) throws IcatException {
URIBuilder uriBuilder = getUriBuilder("search/documents");
uriBuilder.setParameter("sessionId", sessionId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -616,24 +617,19 @@ String searchInvestigations(String sessionId, String user, String text, Date low
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
}
if (samples != null && !samples.isEmpty()) {
gen.writeStartArray("samples");
for (String sample : samples) {
gen.write(sample);
}
gen.writeEnd();
}
if (userFullName != null) {
gen.write("userFullName", userFullName);
}
if (facets != null) {
gen.write("facets", facets);
}
gen.writeEnd();
}

uriBuilder.setParameter("query", baos.toString());
uriBuilder.setParameter("search_after", searchAfter);
uriBuilder.setParameter("limit", Integer.toString(limit));
uriBuilder.setParameter("maxCount", Integer.toString(maxCount));
uriBuilder.setParameter("sort", sort);
uriBuilder.setParameter("facets", facets);
URI uri = getUri(uriBuilder);

try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
Expand Down Expand Up @@ -689,7 +685,7 @@ String searchDatasets(String sessionId, String user, String text, Date lower, Da
}

String searchDatasets(String sessionId, String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, String searchAfter, int limit, String sort, String facets) throws IcatException {
List<ParameterForLucene> parameters, String searchAfter, int maxCount, String sort, JsonArray facets) throws IcatException {
URIBuilder uriBuilder = getUriBuilder("search/documents");
uriBuilder.setParameter("sessionId", sessionId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -711,14 +707,16 @@ String searchDatasets(String sessionId, String user, String text, Date lower, Da
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
}
if (facets != null) {
gen.write("facets", facets);
}
gen.writeEnd();
}

uriBuilder.setParameter("query", baos.toString());
uriBuilder.setParameter("search_after", searchAfter);
uriBuilder.setParameter("limit", Integer.toString(limit));
uriBuilder.setParameter("maxCount", Integer.toString(maxCount));
uriBuilder.setParameter("sort", sort);
uriBuilder.setParameter("facets", facets);
URI uri = getUri(uriBuilder);

try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
Expand Down Expand Up @@ -905,7 +903,7 @@ String searchDatafiles(String sessionId, String user, String text, Date lower, D
}

String searchDatafiles(String sessionId, String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, String searchAfter, int limit, String sort, String facets) throws IcatException {
List<ParameterForLucene> parameters, String searchAfter, int maxCount, String sort, JsonArray facets) throws IcatException {
URIBuilder uriBuilder = getUriBuilder("search/documents");
uriBuilder.setParameter("sessionId", sessionId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -927,14 +925,16 @@ String searchDatafiles(String sessionId, String user, String text, Date lower, D
if (parameters != null && !parameters.isEmpty()) {
writeParameters(gen, parameters);
}
if (facets != null) {
gen.write("facets", facets);
}
gen.writeEnd();
}

uriBuilder.setParameter("query", baos.toString());
uriBuilder.setParameter("search_after", searchAfter);
uriBuilder.setParameter("limit", Integer.toString(limit));
uriBuilder.setParameter("maxCount", Integer.toString(maxCount));
uriBuilder.setParameter("sort", sort);
uriBuilder.setParameter("facets", facets);
URI uri = getUri(uriBuilder);

try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/org/icatproject/icat/client/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.List;
import java.util.Map;

import javax.json.JsonArray;

/**
* A RESTful ICAT session.
* <p>
Expand Down Expand Up @@ -439,7 +441,7 @@ public String searchInvestigations(String user, String text, Date lower, Date up
* String representing the last document of a previous
* search, so that results from this search will only
* include results from after the document
* @param limit
* @param maxCount
* The maximum number of results to return.
* @param sort
* String representing a JSON object which contains key
Expand All @@ -458,11 +460,10 @@ public String searchInvestigations(String user, String text, Date lower, Date up
* For various ICAT errors.
*/
public String searchInvestigations(String user, String text, Date lower, Date upper,
List<ParameterForLucene> parameters, List<String> samples, String userFullName, String searchAfter,
int limit, String sort, String facets)
throws IcatException {
return icat.searchInvestigations(sessionId, user, text, lower, upper, parameters, samples, userFullName,
searchAfter, limit, sort, facets);
List<ParameterForLucene> parameters, String userFullName, String searchAfter, int maxCount, String sort,
JsonArray facets) throws IcatException {
return icat.searchInvestigations(sessionId, user, text, lower, upper, parameters, userFullName,
searchAfter, maxCount, sort, facets);
}

/**
Expand Down Expand Up @@ -523,7 +524,7 @@ public String searchDatasets(String user, String text, Date lower, Date upper, L
* String representing the last document of a previous
* search, so that results from this search will only include
* results from after the document
* @param limit
* @param maxCount
* The maximum number of results to return.
* @param sort
* String representing a JSON object which contains key value
Expand All @@ -541,8 +542,8 @@ public String searchDatasets(String user, String text, Date lower, Date upper, L
* For various ICAT errors.
*/
public String searchDatasets(String user, String text, Date lower, Date upper, List<ParameterForLucene> parameters,
String searchAfter, int limit, String sort, String facets) throws IcatException {
return icat.searchDatasets(sessionId, user, text, lower, upper, parameters, searchAfter, limit, sort, facets);
String searchAfter, int maxCount, String sort, JsonArray facets) throws IcatException {
return icat.searchDatasets(sessionId, user, text, lower, upper, parameters, searchAfter, maxCount, sort, facets);
}

/**
Expand Down Expand Up @@ -650,7 +651,7 @@ public String searchDatafiles(String user, String text, Date lower, Date upper,
* String representing the last document of a previous
* search, so that results from this search will only include
* results from after the document
* @param limit
* @param maxCount
* The maximum number of results to return.
* @param sort
* String representing a JSON object which contains key value
Expand All @@ -668,8 +669,8 @@ public String searchDatafiles(String user, String text, Date lower, Date upper,
* For various ICAT errors.
*/
public String searchDatafiles(String user, String text, Date lower, Date upper, List<ParameterForLucene> parameters,
String searchAfter, int limit, String sort, String facets) throws IcatException {
return icat.searchDatafiles(sessionId, user, text, lower, upper, parameters, searchAfter, limit, sort, facets);
String searchAfter, int maxCount, String sort, JsonArray facets) throws IcatException {
return icat.searchDatafiles(sessionId, user, text, lower, upper, parameters, searchAfter, maxCount, sort, facets);
}

/**
Expand Down

0 comments on commit 50dbf32

Please sign in to comment.