Search in sources :

Example 26 with QueryResponse

use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse 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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)

Aggregations

QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)23 Test (org.junit.Test)23 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)20 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)20 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)5 Calculation (com.ibm.watson.developer_cloud.discovery.v1.model.Calculation)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)3 FederatedQueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.FederatedQueryOptions)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Ignore (org.junit.Ignore)3 JsonObject (com.google.gson.JsonObject)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)2 Term (com.ibm.watson.developer_cloud.discovery.v1.model.Term)2 ArrayList (java.util.ArrayList)2 AggregationResult (com.ibm.watson.developer_cloud.discovery.v1.model.AggregationResult)1