use of com.ibm.watson.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithNestedAggregationTermIsSuccessful.
@Test
public void queryWithNestedAggregationTermIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
createTestDocument("test_document_1", collectionId);
createTestDocument("test_document_2", collectionId);
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);
sb.append(Operator.NEST_AGGREGATION);
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 queryResponse = discovery.query(queryBuilder.build()).execute();
Term term = (Term) queryResponse.getAggregations().get(0);
AggregationResult agResults = term.getResults().get(0);
List<QueryAggregation> aggregations = agResults.getAggregations();
assertFalse(aggregations.isEmpty());
}
use of com.ibm.watson.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method issueNumber654.
@Test
public void issueNumber654() {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
queryBuilder.query("field:1|3");
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
assertEquals(new Long(2), queryResponse.getMatchingResults());
assertEquals(2, queryResponse.getResults().size());
}
use of com.ibm.watson.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateDocumentWithMetadataIsSuccessful.
@Test
@Ignore("Pending implementation of 'processing' after document update")
public void updateDocumentWithMetadataIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
UpdateDocumentOptions.Builder updateBuilder = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId());
updateBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
updateBuilder.metadata(myMetadata.toString());
DocumentAccepted updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
WaitFor.Condition waitForDocumentAccepted = new WaitForDocumentAccepted(environmentId, collectionId, updateResponse.getDocumentId());
WaitFor.waitFor(waitForDocumentAccepted, 5, TimeUnit.SECONDS, 500);
QueryOptions queryOptions = new QueryOptions.Builder(environmentId, collectionId).build();
QueryResponse queryResponse = discovery.query(queryOptions).execute();
assertTrue(queryResponse.getResults().get(0).getMetadata() != null);
}
use of com.ibm.watson.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithPassagesIsSuccessful.
@Test
public void queryWithPassagesIsSuccessful() throws InterruptedException, FileNotFoundException {
Collection testCollection = createTestCollection();
String collectionId = testCollection.getCollectionId();
createTestDocument(getStringFromInputStream(new FileInputStream(PASSAGES_TEST_FILE_1)), "test_document_1", collectionId);
createTestDocument(getStringFromInputStream(new FileInputStream(PASSAGES_TEST_FILE_2)), "test_document_2", collectionId);
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
queryBuilder.passages(true);
queryBuilder.naturalLanguageQuery("Watson");
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
List<QueryPassages> passages = queryResponse.getPassages();
assertTrue(passages.size() > 0);
for (QueryPassages passage : passages) {
assertTrue(passage.getPassageText().contains("Watson"));
}
}
use of com.ibm.watson.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithAggregationSummationIsSuccessful.
@Test
public void queryWithAggregationSummationIsSuccessful() throws InterruptedException {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.SUM);
sb.append(Operator.OPENING_GROUPING);
sb.append("field");
sb.append(Operator.CLOSING_GROUPING);
String aggregation = sb.toString();
queryBuilder.aggregation(aggregation);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
Calculation sum = (Calculation) queryResponse.getAggregations().get(0);
assertEquals(AggregationType.SUM.getName(), sum.getType());
assertEquals(new Double(45), sum.getValue());
}
Aggregations