From 8d53d6c71b6ef6fb31119ed5bcd082e1bf6dcbb6 Mon Sep 17 00:00:00 2001 From: Kevin Kowalski Date: Tue, 14 Sep 2021 09:32:36 -0500 Subject: [PATCH] fix(assistant-v2): add answers to searchResult --- .../assistant/v2/model/SearchResult.java | 18 ++++++++ .../v2/model/SearchResultAnswer.java | 46 +++++++++++++++++++ .../assistant/v2/model/SearchResultTest.java | 3 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResultAnswer.java diff --git a/assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResult.java b/assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResult.java index db1f28b3a31..b784d651f86 100644 --- a/assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResult.java +++ b/assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResult.java @@ -14,6 +14,7 @@ import com.google.gson.annotations.SerializedName; import com.ibm.cloud.sdk.core.service.model.GenericModel; +import java.util.List; /** SearchResult. */ public class SearchResult extends GenericModel { @@ -27,6 +28,7 @@ public class SearchResult extends GenericModel { protected String title; protected String url; protected SearchResultHighlight highlight; + protected List answers; /** * Gets the id. @@ -99,4 +101,20 @@ public String getUrl() { public SearchResultHighlight getHighlight() { return highlight; } + + /** + * Gets the answers. + * + *

An array specifying segments of text within the result that were identified as direct + * answers to the search query. Currently, only the single answer with the highest confidence (if + * any) is returned. + * + *

**Note:** This property uses the answer finding beta feature, and is available only if the + * search skill is connected to a Discovery v2 service instance. + * + * @return the answers + */ + public List getAnswers() { + return answers; + } } diff --git a/assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResultAnswer.java b/assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResultAnswer.java new file mode 100644 index 00000000000..510a9edb8b9 --- /dev/null +++ b/assistant/src/main/java/com/ibm/watson/assistant/v2/model/SearchResultAnswer.java @@ -0,0 +1,46 @@ +/* + * (C) Copyright IBM Corp. 2021. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.watson.assistant.v2.model; + +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * An object specifing a segment of text that was identified as a direct answer to the search query. + */ +public class SearchResultAnswer extends GenericModel { + + protected String text; + protected Double confidence; + + /** + * Gets the text. + * + *

The text of the answer. + * + * @return the text + */ + public String getText() { + return text; + } + + /** + * Gets the confidence. + * + *

The confidence score for the answer, as returned by the Discovery service. + * + * @return the confidence + */ + public Double getConfidence() { + return confidence; + } +} diff --git a/assistant/src/test/java/com/ibm/watson/assistant/v2/model/SearchResultTest.java b/assistant/src/test/java/com/ibm/watson/assistant/v2/model/SearchResultTest.java index d9746d467de..7bd307c0095 100644 --- a/assistant/src/test/java/com/ibm/watson/assistant/v2/model/SearchResultTest.java +++ b/assistant/src/test/java/com/ibm/watson/assistant/v2/model/SearchResultTest.java @@ -1,5 +1,5 @@ /* - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -37,5 +37,6 @@ public void testSearchResult() throws Throwable { assertNull(searchResultModel.getTitle()); assertNull(searchResultModel.getUrl()); assertNull(searchResultModel.getHighlight()); + assertNull(searchResultModel.getAnswers()); } }