Skip to content

Commit b5a78e7

Browse files
authored
Merge pull request #403 from watson-developer-cloud/4.0.0/regeneration
Regeneration
2 parents 3f3c5a4 + 3fe84a5 commit b5a78e7

File tree

4 files changed

+87
-8
lines changed

4 files changed

+87
-8
lines changed

src/IBM.Watson.Discovery.v1/DiscoveryService.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,13 +2815,13 @@ public DetailedResponse<QueryNoticesResponse> FederatedQueryNotices(string envir
28152815
/// </summary>
28162816
/// <param name="environmentId">The ID of the environment.</param>
28172817
/// <param name="collectionId">The ID of the collection.</param>
2818+
/// <param name="prefix">The prefix to use for autocompletion. For example, the prefix `Ho` could autocomplete
2819+
/// to `Hot`, `Housing`, or `How do I upgrade`. Possible completions are.</param>
28182820
/// <param name="field">The field in the result documents that autocompletion suggestions are identified from.
28192821
/// (optional)</param>
2820-
/// <param name="prefix">The prefix to use for autocompletion. For example, the prefix `Ho` could autocomplete
2821-
/// to `Hot`, `Housing`, or `How do I upgrade`. Possible completions are. (optional)</param>
28222822
/// <param name="count">The number of autocompletion suggestions to return. (optional)</param>
28232823
/// <returns><see cref="Completions" />Completions</returns>
2824-
public DetailedResponse<Completions> GetAutocompletion(string environmentId, string collectionId, string field = null, string prefix = null, long? count = null)
2824+
public DetailedResponse<Completions> GetAutocompletion(string environmentId, string collectionId, string prefix, string field = null, long? count = null)
28252825
{
28262826
if (string.IsNullOrEmpty(environmentId))
28272827
{
@@ -2839,6 +2839,10 @@ public DetailedResponse<Completions> GetAutocompletion(string environmentId, str
28392839
{
28402840
collectionId = Uri.EscapeDataString(collectionId);
28412841
}
2842+
if (string.IsNullOrEmpty(prefix))
2843+
{
2844+
throw new ArgumentNullException("`prefix` is required for `GetAutocompletion`");
2845+
}
28422846

28432847
if (string.IsNullOrEmpty(VersionDate))
28442848
{
@@ -2856,14 +2860,14 @@ public DetailedResponse<Completions> GetAutocompletion(string environmentId, str
28562860

28572861
restRequest.WithArgument("version", VersionDate);
28582862
restRequest.WithHeader("Accept", "application/json");
2859-
if (!string.IsNullOrEmpty(field))
2860-
{
2861-
restRequest.WithArgument("field", field);
2862-
}
28632863
if (!string.IsNullOrEmpty(prefix))
28642864
{
28652865
restRequest.WithArgument("prefix", prefix);
28662866
}
2867+
if (!string.IsNullOrEmpty(field))
2868+
{
2869+
restRequest.WithArgument("field", field);
2870+
}
28672871
if (count != null)
28682872
{
28692873
restRequest.WithArgument("count", count);

src/IBM.Watson.Discovery.v1/IDiscoveryService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public partial interface IDiscoveryService
5959
DetailedResponse<QueryNoticesResponse> QueryNotices(string environmentId, string collectionId, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, List<string> _return = null, long? offset = null, List<string> sort = null, bool? highlight = null, List<string> passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null);
6060
DetailedResponse<QueryResponse> FederatedQuery(string environmentId, string collectionIds, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, string _return = null, long? offset = null, string sort = null, bool? highlight = null, string passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, string similarDocumentIds = null, string similarFields = null, string bias = null, bool? xWatsonLoggingOptOut = null);
6161
DetailedResponse<QueryNoticesResponse> FederatedQueryNotices(string environmentId, List<string> collectionIds, string filter = null, string query = null, string naturalLanguageQuery = null, string aggregation = null, long? count = null, List<string> _return = null, long? offset = null, List<string> sort = null, bool? highlight = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null);
62-
DetailedResponse<Completions> GetAutocompletion(string environmentId, string collectionId, string field = null, string prefix = null, long? count = null);
62+
DetailedResponse<Completions> GetAutocompletion(string environmentId, string collectionId, string prefix, string field = null, long? count = null);
6363
DetailedResponse<TrainingDataSet> ListTrainingData(string environmentId, string collectionId);
6464
DetailedResponse<TrainingQuery> AddTrainingData(string environmentId, string collectionId, string naturalLanguageQuery = null, string filter = null, List<TrainingExample> examples = null);
6565
DetailedResponse<object> DeleteAllTrainingData(string environmentId, string collectionId);

src/IBM.Watson.Discovery.v1/Model/QueryResponse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public class QueryResponse
6363
/// </summary>
6464
[JsonProperty("retrieval_details", NullValueHandling = NullValueHandling.Ignore)]
6565
public RetrievalDetails RetrievalDetails { get; set; }
66+
/// <summary>
67+
/// The suggestions for a misspelled natural language query.
68+
/// </summary>
69+
[JsonProperty("suggested_query", NullValueHandling = NullValueHandling.Ignore)]
70+
public string SuggestedQuery { get; set; }
6671
}
6772

6873
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright 2019 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using IBM.Cloud.SDK.Core.Authentication.Bearer;
19+
using Microsoft.VisualStudio.TestTools.UnitTesting;
20+
21+
namespace IBM.Watson.Discovery.v1.IntegrationTests
22+
{
23+
[TestClass]
24+
public class DiscoveryCpdIntegrationTests
25+
{
26+
private DiscoveryService service;
27+
private string environmentId;
28+
private string collectionId;
29+
private string bearerToken;
30+
private string serviceUrl;
31+
32+
[TestInitialize]
33+
public void Setup()
34+
{
35+
BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(
36+
bearerToken: bearerToken
37+
);
38+
service = new DiscoveryService("2019-10-03", authenticator);
39+
service.SetServiceUrl(serviceUrl);
40+
service.DisableSslVerification(true);
41+
42+
var listEnvironmentsResult = service.ListEnvironments();
43+
44+
environmentId = listEnvironmentsResult.Result.Environments[0].EnvironmentId;
45+
46+
var listCollectionsResult = service.ListCollections(environmentId: environmentId);
47+
48+
collectionId = listCollectionsResult.Result.Collections[0].CollectionId;
49+
}
50+
51+
[TestMethod]
52+
public void TestAutocompletion()
53+
{
54+
var autoCompletionResult = service.GetAutocompletion(environmentId: environmentId, collectionId: collectionId, prefix: "ho");
55+
56+
Assert.IsNotNull(autoCompletionResult.Result);
57+
Assert.IsNotNull(autoCompletionResult.Result._Completions);
58+
Assert.IsNotNull(autoCompletionResult.Result._Completions[0]);
59+
}
60+
61+
[TestMethod]
62+
public void TestSpellingSuggestions()
63+
{
64+
var queryResult = service.Query(environmentId: environmentId, collectionId: collectionId, naturalLanguageQuery: "cluod", spellingSuggestions: true);
65+
66+
Assert.IsNotNull(queryResult.Result);
67+
Assert.IsNotNull(queryResult.Result.SuggestedQuery);
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)