use of com.ibm.watson.discovery.v2.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithQueryIsSuccessful.
@Ignore
@Test
public void queryWithQueryIsSuccessful() {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
queryBuilder.query("field" + Operator.CONTAINS + 1);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
assertEquals(new Long(1), queryResponse.getMatchingResults());
assertEquals(1, queryResponse.getResults().size());
assertTrue(queryResponse.getResults().get(0).getScore() > 1.0);
}
use of com.ibm.watson.discovery.v2.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithSortIsSuccessful.
@Test
public void queryWithSortIsSuccessful() {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
ArrayList<String> sortList = new ArrayList<>();
sortList.add("field");
queryBuilder.sort(sortList);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
assertTrue(queryResponse.getResults().size() > 1);
Double v0 = (Double) (queryResponse.getResults().get(0)).get("field");
Double v1 = (Double) (queryResponse.getResults().get(1)).get("field");
assertTrue(v0 <= v1);
}
use of com.ibm.watson.discovery.v2.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithAggregationHistogramIsSuccessful.
@Test
public void queryWithAggregationHistogramIsSuccessful() throws InterruptedException {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.HISTOGRAM);
sb.append(Operator.OPENING_GROUPING);
sb.append("field");
sb.append(Operator.AND);
sb.append(5L);
sb.append(Operator.CLOSING_GROUPING);
String aggregation = sb.toString();
queryBuilder.aggregation(aggregation);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
Histogram histogram = (Histogram) queryResponse.getAggregations().get(0);
Long interval = histogram.getInterval();
assertEquals(new Long(5), interval);
assertEquals(2, histogram.getResults().size());
}
use of com.ibm.watson.discovery.v2.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method federatedQueryIsSuccessful.
@Test
public void federatedQueryIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(queryResp));
FederatedQueryOptions.Builder builder = new FederatedQueryOptions.Builder(environmentId, new ArrayList<>(Arrays.asList(collectionId)));
QueryResponse response = discoveryService.federatedQuery(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(Q3_PATH, request.getPath());
assertEquals(GET, request.getMethod());
}
use of com.ibm.watson.discovery.v2.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method queryWithAggregationTermIsSuccessful.
@Test
public void queryWithAggregationTermIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(queryResp));
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.TERM);
sb.append(Operator.OPENING_GROUPING);
sb.append("field");
sb.append(Operator.CLOSING_GROUPING);
String aggregation = sb.toString();
queryBuilder.aggregation(aggregation);
QueryResponse response = discoveryService.query(queryBuilder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(Q2_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(GsonSingleton.getGson().toJsonTree(queryResp), GsonSingleton.getGson().toJsonTree(response));
}
Aggregations