use of com.ibm.watson.developer_cloud.discovery.v1.model.FederatedQueryOptions in project java-sdk by watson-developer-cloud.
the class Discovery method federatedQuery.
/**
* Query documents in multiple collections.
*
* See the [Discovery service documentation](https://console.bluemix.net/docs/services/discovery/using.html) for more
* details.
*
* @param federatedQueryOptions the {@link FederatedQueryOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link QueryResponse}
*/
public ServiceCall<QueryResponse> federatedQuery(FederatedQueryOptions federatedQueryOptions) {
Validator.notNull(federatedQueryOptions, "federatedQueryOptions cannot be null");
String[] pathSegments = { "v1/environments", "query" };
String[] pathParameters = { federatedQueryOptions.environmentId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
builder.query("collection_ids", RequestUtils.join(federatedQueryOptions.collectionIds(), ","));
if (federatedQueryOptions.filter() != null) {
builder.query("filter", federatedQueryOptions.filter());
}
if (federatedQueryOptions.query() != null) {
builder.query("query", federatedQueryOptions.query());
}
if (federatedQueryOptions.naturalLanguageQuery() != null) {
builder.query("natural_language_query", federatedQueryOptions.naturalLanguageQuery());
}
if (federatedQueryOptions.aggregation() != null) {
builder.query("aggregation", federatedQueryOptions.aggregation());
}
if (federatedQueryOptions.count() != null) {
builder.query("count", String.valueOf(federatedQueryOptions.count()));
}
if (federatedQueryOptions.returnFields() != null) {
builder.query("return_fields", RequestUtils.join(federatedQueryOptions.returnFields(), ","));
}
if (federatedQueryOptions.offset() != null) {
builder.query("offset", String.valueOf(federatedQueryOptions.offset()));
}
if (federatedQueryOptions.sort() != null) {
builder.query("sort", RequestUtils.join(federatedQueryOptions.sort(), ","));
}
if (federatedQueryOptions.highlight() != null) {
builder.query("highlight", String.valueOf(federatedQueryOptions.highlight()));
}
if (federatedQueryOptions.deduplicate() != null) {
builder.query("deduplicate", String.valueOf(federatedQueryOptions.deduplicate()));
}
if (federatedQueryOptions.deduplicateField() != null) {
builder.query("deduplicate.field", federatedQueryOptions.deduplicateField());
}
if (federatedQueryOptions.similar() != null) {
builder.query("similar", String.valueOf(federatedQueryOptions.similar()));
}
if (federatedQueryOptions.similarDocumentIds() != null) {
builder.query("similar.document_ids", RequestUtils.join(federatedQueryOptions.similarDocumentIds(), ","));
}
if (federatedQueryOptions.similarFields() != null) {
builder.query("similar.fields", RequestUtils.join(federatedQueryOptions.similarFields(), ","));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(QueryResponse.class));
}
Aggregations