Discovery extends BaseService { public ServiceCall<QueryResponse> query(QueryOptions queryOptions) { com.ibm.cloud.sdk.core.util.Validator.notNull(queryOptions, "queryOptions cannot be null"); String[] pathSegments = {"v2/projects", "query"}; String[] pathParameters = {queryOptions.projectId()}; RequestBuilder builder = RequestBuilder.post( RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments, pathParameters)); builder.query("version", versionDate); Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "query"); for (Entry<String, String> header : sdkHeaders.entrySet()) { builder.header(header.getKey(), header.getValue()); } builder.header("Accept", "application/json"); final JsonObject contentJson = new JsonObject(); if (queryOptions.collectionIds() != null) { contentJson.add( "collection_ids", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson() .toJsonTree(queryOptions.collectionIds())); } if (queryOptions.filter() != null) { contentJson.addProperty("filter", queryOptions.filter()); } if (queryOptions.query() != null) { contentJson.addProperty("query", queryOptions.query()); } if (queryOptions.naturalLanguageQuery() != null) { contentJson.addProperty("natural_language_query", queryOptions.naturalLanguageQuery()); } if (queryOptions.aggregation() != null) { contentJson.addProperty("aggregation", queryOptions.aggregation()); } if (queryOptions.count() != null) { contentJson.addProperty("count", queryOptions.count()); } if (queryOptions.xReturn() != null) { contentJson.add( "return", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(queryOptions.xReturn())); } if (queryOptions.offset() != null) { contentJson.addProperty("offset", queryOptions.offset()); } if (queryOptions.sort() != null) { contentJson.addProperty("sort", queryOptions.sort()); } if (queryOptions.highlight() != null) { contentJson.addProperty("highlight", queryOptions.highlight()); } if (queryOptions.spellingSuggestions() != null) { contentJson.addProperty("spelling_suggestions", queryOptions.spellingSuggestions()); } if (queryOptions.tableResults() != null) { contentJson.add( "table_results", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson() .toJsonTree(queryOptions.tableResults())); } if (queryOptions.suggestedRefinements() != null) { contentJson.add( "suggested_refinements", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson() .toJsonTree(queryOptions.suggestedRefinements())); } if (queryOptions.passages() != null) { contentJson.add( "passages", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(queryOptions.passages())); } builder.bodyJson(contentJson); ResponseConverter<QueryResponse> responseConverter = ResponseConverterUtils.getValue( new com.google.gson.reflect.TypeToken<QueryResponse>() {}.getType()); return createServiceCall(builder.build(), responseConverter); } Discovery(String versionDate);  Discovery(String versionDate, Authenticator authenticator);  Discovery(String versionDate, String serviceName);  Discovery(String versionDate, String serviceName, Authenticator authenticator); ServiceCall<ListCollectionsResponse> listCollections(
      ListCollectionsOptions listCollectionsOptions); ServiceCall<CollectionDetails> createCollection(
      CreateCollectionOptions createCollectionOptions); ServiceCall<CollectionDetails> getCollection(GetCollectionOptions getCollectionOptions); ServiceCall<CollectionDetails> updateCollection(
      UpdateCollectionOptions updateCollectionOptions); ServiceCall<Void> deleteCollection(DeleteCollectionOptions deleteCollectionOptions); ServiceCall<QueryResponse> query(QueryOptions queryOptions); ServiceCall<Completions> getAutocompletion(
      GetAutocompletionOptions getAutocompletionOptions); ServiceCall<QueryNoticesResponse> queryNotices(QueryNoticesOptions queryNoticesOptions); ServiceCall<ListFieldsResponse> listFields(ListFieldsOptions listFieldsOptions); ServiceCall<ComponentSettingsResponse> getComponentSettings(
      GetComponentSettingsOptions getComponentSettingsOptions); ServiceCall<DocumentAccepted> addDocument(AddDocumentOptions addDocumentOptions); ServiceCall<DocumentAccepted> updateDocument(UpdateDocumentOptions updateDocumentOptions); ServiceCall<DeleteDocumentResponse> deleteDocument(
      DeleteDocumentOptions deleteDocumentOptions); ServiceCall<TrainingQuerySet> listTrainingQueries(
      ListTrainingQueriesOptions listTrainingQueriesOptions); ServiceCall<Void> deleteTrainingQueries(
      DeleteTrainingQueriesOptions deleteTrainingQueriesOptions); ServiceCall<TrainingQuery> createTrainingQuery(
      CreateTrainingQueryOptions createTrainingQueryOptions); ServiceCall<TrainingQuery> getTrainingQuery(
      GetTrainingQueryOptions getTrainingQueryOptions); ServiceCall<TrainingQuery> updateTrainingQuery(
      UpdateTrainingQueryOptions updateTrainingQueryOptions); ServiceCall<Enrichments> listEnrichments(ListEnrichmentsOptions listEnrichmentsOptions); ServiceCall<Enrichment> createEnrichment(CreateEnrichmentOptions createEnrichmentOptions); ServiceCall<Enrichment> getEnrichment(GetEnrichmentOptions getEnrichmentOptions); ServiceCall<Enrichment> updateEnrichment(UpdateEnrichmentOptions updateEnrichmentOptions); ServiceCall<Void> deleteEnrichment(DeleteEnrichmentOptions deleteEnrichmentOptions); ServiceCall<ListProjectsResponse> listProjects(ListProjectsOptions listProjectsOptions); ServiceCall<ListProjectsResponse> listProjects(); ServiceCall<ProjectDetails> createProject(CreateProjectOptions createProjectOptions); ServiceCall<ProjectDetails> getProject(GetProjectOptions getProjectOptions); ServiceCall<ProjectDetails> updateProject(UpdateProjectOptions updateProjectOptions); ServiceCall<Void> deleteProject(DeleteProjectOptions deleteProjectOptions); ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOptions);  }
@Test public void testQueryNoticesOptions() { QueryNoticesOptions options = new QueryNoticesOptions.Builder() .projectId(PROJECT_ID) .filter(FILTER) .query(QUERY) .naturalLanguageQuery(NATURAL_LANGUAGE_QUERY) .count(COUNT) .offset(OFFSET) .build(); options = options.newBuilder().build(); assertEquals(PROJECT_ID, options.projectId()); assertEquals(FILTER, options.filter()); assertEquals(QUERY, options.query()); assertEquals(NATURAL_LANGUAGE_QUERY, options.naturalLanguageQuery()); assertEquals(COUNT, options.count()); assertEquals(OFFSET, options.offset()); }
@Test public void testQueryOptions() { List<String> collectionIds = new ArrayList<>(); collectionIds.add(COLLECTION_ID); List<String> returnList = new ArrayList<>(); returnList.add(RETURN); QueryOptions options = new QueryOptions.Builder() .projectId(PROJECT_ID) .collectionIds(collectionIds) .addCollectionIds(COLLECTION_ID) .filter(FILTER) .query(QUERY) .naturalLanguageQuery(NATURAL_LANGUAGE_QUERY) .aggregation(AGGREGATION) .count(COUNT) .xReturn(returnList) .addReturnField(RETURN) .offset(OFFSET) .sort(SORT) .highlight(true) .spellingSuggestions(true) .tableResults(queryLargeTableResults) .suggestedRefinements(queryLargeSuggestedRefinements) .passages(queryLargePassages) .build(); options = options.newBuilder().build(); assertEquals(PROJECT_ID, options.projectId()); assertEquals(FILTER, options.filter()); assertEquals(QUERY, options.query()); assertEquals(NATURAL_LANGUAGE_QUERY, options.naturalLanguageQuery()); assertEquals(AGGREGATION, options.aggregation()); assertEquals(COUNT, options.count()); assertEquals(2, options.xReturn().size()); assertEquals(RETURN, options.xReturn().get(0)); assertEquals(OFFSET, options.offset()); assertEquals(SORT, options.sort()); assertTrue(options.highlight()); assertTrue(options.spellingSuggestions()); assertEquals(queryLargeTableResults, options.tableResults()); assertEquals(queryLargeSuggestedRefinements, options.suggestedRefinements()); assertEquals(queryLargePassages, options.passages()); }
@Test public void testQuery() { server.enqueue(jsonResponse(queryResponse)); QueryOptions options = new QueryOptions.Builder().projectId(PROJECT_ID).build(); QueryResponse response = service.query(options).execute().getResult(); assertEquals(MATCHING_RESULTS, response.getMatchingResults()); assertEquals(DOCUMENT_ID, response.getResults().get(0).getDocumentId()); assertEquals( DOCUMENT_RETRIEVAL_SOURCE, response.getResults().get(0).getResultMetadata().getDocumentRetrievalSource()); assertEquals(COLLECTION_ID, response.getResults().get(0).getResultMetadata().getCollectionId()); assertEquals(CONFIDENCE, response.getResults().get(0).getResultMetadata().getConfidence()); assertEquals( PASSAGE_TEXT, response.getResults().get(0).getDocumentPassages().get(0).getPassageText()); assertEquals( START_OFFSET, response.getResults().get(0).getDocumentPassages().get(0).getStartOffset()); assertEquals( END_OFFSET, response.getResults().get(0).getDocumentPassages().get(0).getEndOffset()); assertEquals(FIELD, response.getResults().get(0).getDocumentPassages().get(0).getField()); assertEquals( DOCUMENT_RETRIEVAL_STRATEGY, response.getRetrievalDetails().getDocumentRetrievalStrategy()); assertEquals(SUGGESTED_QUERY, response.getSuggestedQuery()); assertEquals(TEXT, response.getSuggestedRefinements().get(0).getText()); assertEquals(TABLE_ID, response.getTableResults().get(0).getTableId()); assertEquals(SOURCE_DOCUMENT_ID, response.getTableResults().get(0).getSourceDocumentId()); assertEquals(COLLECTION_ID, response.getTableResults().get(0).getCollectionId()); assertEquals(TABLE_HTML, response.getTableResults().get(0).getTableHtml()); assertEquals(TABLE_HTML_OFFSET, response.getTableResults().get(0).getTableHtmlOffset()); assertEquals(BEGIN, response.getTableResults().get(0).getTable().getLocation().getBegin()); assertEquals(END, response.getTableResults().get(0).getTable().getLocation().getEnd()); assertEquals(TEXT, response.getTableResults().get(0).getTable().getText()); assertEquals(TEXT, response.getTableResults().get(0).getTable().getSectionTitle().getText()); assertEquals( BEGIN, response.getTableResults().get(0).getTable().getSectionTitle().getLocation().getBegin()); assertEquals( END, response.getTableResults().get(0).getTable().getSectionTitle().getLocation().getEnd()); assertEquals(TEXT, response.getTableResults().get(0).getTable().getTitle().getText()); assertEquals( BEGIN, response.getTableResults().get(0).getTable().getTitle().getLocation().getBegin()); assertEquals( END, response.getTableResults().get(0).getTable().getTitle().getLocation().getEnd()); assertEquals( CELL_ID, response.getTableResults().get(0).getTable().getTableHeaders().get(0).getCellId()); assertEquals( TEXT, response.getTableResults().get(0).getTable().getTableHeaders().get(0).getText()); assertEquals( ROW_INDEX_BEGIN, response.getTableResults().get(0).getTable().getTableHeaders().get(0).getRowIndexBegin()); assertEquals( ROW_INDEX_END, response.getTableResults().get(0).getTable().getTableHeaders().get(0).getRowIndexEnd()); assertEquals( COLUMN_INDEX_BEGIN, response .getTableResults() .get(0) .getTable() .getTableHeaders() .get(0) .getColumnIndexBegin()); assertEquals( COLUMN_INDEX_END, response.getTableResults().get(0).getTable().getTableHeaders().get(0).getColumnIndexEnd()); assertEquals( CELL_ID, response.getTableResults().get(0).getTable().getRowHeaders().get(0).getCellId()); assertEquals( BEGIN, response .getTableResults() .get(0) .getTable() .getRowHeaders() .get(0) .getLocation() .getBegin()); assertEquals( END, response.getTableResults().get(0).getTable().getRowHeaders().get(0).getLocation().getEnd()); assertEquals( TEXT, response.getTableResults().get(0).getTable().getRowHeaders().get(0).getText()); assertEquals( ROW_INDEX_BEGIN, response.getTableResults().get(0).getTable().getRowHeaders().get(0).getRowIndexBegin()); assertEquals( ROW_INDEX_END, response.getTableResults().get(0).getTable().getRowHeaders().get(0).getRowIndexEnd()); assertEquals( COLUMN_INDEX_BEGIN, response.getTableResults().get(0).getTable().getRowHeaders().get(0).getColumnIndexBegin()); assertEquals( COLUMN_INDEX_END, response.getTableResults().get(0).getTable().getRowHeaders().get(0).getColumnIndexEnd()); assertEquals( CELL_ID, response.getTableResults().get(0).getTable().getColumnHeaders().get(0).getCellId()); assertEquals( TEXT, response.getTableResults().get(0).getTable().getColumnHeaders().get(0).getText()); assertEquals( ROW_INDEX_BEGIN, response.getTableResults().get(0).getTable().getColumnHeaders().get(0).getRowIndexBegin()); assertEquals( ROW_INDEX_END, response.getTableResults().get(0).getTable().getColumnHeaders().get(0).getRowIndexEnd()); assertEquals( COLUMN_INDEX_BEGIN, response .getTableResults() .get(0) .getTable() .getColumnHeaders() .get(0) .getColumnIndexBegin()); assertEquals( COLUMN_INDEX_END, response.getTableResults().get(0).getTable().getColumnHeaders().get(0).getColumnIndexEnd()); assertEquals( CELL_ID, response .getTableResults() .get(0) .getTable() .getKeyValuePairs() .get(0) .getKey() .getCellId()); assertEquals( BEGIN, response .getTableResults() .get(0) .getTable() .getKeyValuePairs() .get(0) .getKey() .getLocation() .getBegin()); assertEquals( END, response .getTableResults() .get(0) .getTable() .getKeyValuePairs() .get(0) .getKey() .getLocation() .getEnd()); assertEquals( TEXT, response.getTableResults().get(0).getTable().getKeyValuePairs().get(0).getKey().getText()); assertEquals( CELL_ID, response .getTableResults() .get(0) .getTable() .getKeyValuePairs() .get(0) .getValue() .get(0) .getCellId()); assertEquals( BEGIN, response .getTableResults() .get(0) .getTable() .getKeyValuePairs() .get(0) .getValue() .get(0) .getLocation() .getBegin()); assertEquals( END, response .getTableResults() .get(0) .getTable() .getKeyValuePairs() .get(0) .getValue() .get(0) .getLocation() .getEnd()); assertEquals( TEXT, response .getTableResults() .get(0) .getTable() .getKeyValuePairs() .get(0) .getValue() .get(0) .getText()); assertEquals( CELL_ID, response.getTableResults().get(0).getTable().getBodyCells().get(0).getCellId()); assertEquals( BEGIN, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getLocation() .getBegin()); assertEquals( END, response.getTableResults().get(0).getTable().getBodyCells().get(0).getLocation().getEnd()); assertEquals( TEXT, response.getTableResults().get(0).getTable().getBodyCells().get(0).getText()); assertEquals( ROW_INDEX_BEGIN, response.getTableResults().get(0).getTable().getBodyCells().get(0).getRowIndexBegin()); assertEquals( ROW_INDEX_END, response.getTableResults().get(0).getTable().getBodyCells().get(0).getRowIndexEnd()); assertEquals( COLUMN_INDEX_BEGIN, response.getTableResults().get(0).getTable().getBodyCells().get(0).getColumnIndexBegin()); assertEquals( COLUMN_INDEX_END, response.getTableResults().get(0).getTable().getBodyCells().get(0).getColumnIndexEnd()); assertEquals( ID, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getRowHeaderIds() .get(0) .getId()); assertEquals( TEXT, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getRowHeaderTexts() .get(0) .getText()); assertEquals( TEXT_NORMALIZED, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getRowHeaderTextsNormalized() .get(0) .getTextNormalized()); assertEquals( ID, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getColumnHeaderIds() .get(0) .getId()); assertEquals( TEXT, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getColumnHeaderTexts() .get(0) .getText()); assertEquals( TEXT_NORMALIZED, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getColumnHeaderTextsNormalized() .get(0) .getTextNormalized()); assertEquals( TYPE, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getAttributes() .get(0) .getType()); assertEquals( TEXT, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getAttributes() .get(0) .getText()); assertEquals( BEGIN, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getAttributes() .get(0) .getLocation() .getBegin()); assertEquals( END, response .getTableResults() .get(0) .getTable() .getBodyCells() .get(0) .getAttributes() .get(0) .getLocation() .getEnd()); assertEquals(TEXT, response.getTableResults().get(0).getTable().getContexts().get(0).getText()); assertEquals( BEGIN, response.getTableResults().get(0).getTable().getContexts().get(0).getLocation().getBegin()); assertEquals( END, response.getTableResults().get(0).getTable().getContexts().get(0).getLocation().getEnd()); }