Search in sources :

Example 1 with Term

use of com.ibm.watson.developer_cloud.discovery.v1.model.Term in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method queryWithAggregationTermIsSuccessful.

@Test
public void queryWithAggregationTermIsSuccessful() {
    String collectionId = setupTestDocuments();
    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.AND);
    sb.append(10L);
    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);
    assertEquals(1, queryResponse.getAggregations().size());
    assertEquals(new Long(10), term.getCount());
}
Also used : QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse) Term(com.ibm.watson.developer_cloud.discovery.v1.model.Term) QueryOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with Term

use of com.ibm.watson.developer_cloud.discovery.v1.model.Term 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());
}
Also used : AggregationResult(com.ibm.watson.developer_cloud.discovery.v1.model.AggregationResult) QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Term(com.ibm.watson.developer_cloud.discovery.v1.model.Term) QueryAggregation(com.ibm.watson.developer_cloud.discovery.v1.model.QueryAggregation) QueryOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)2 QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)2 Term (com.ibm.watson.developer_cloud.discovery.v1.model.Term)2 Test (org.junit.Test)2 AggregationResult (com.ibm.watson.developer_cloud.discovery.v1.model.AggregationResult)1 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)1 QueryAggregation (com.ibm.watson.developer_cloud.discovery.v1.model.QueryAggregation)1