diff --git a/sdk/search/Azure.Search.Documents/CHANGELOG.md b/sdk/search/Azure.Search.Documents/CHANGELOG.md index 8bea0751336b6..f675d4bbfe753 100644 --- a/sdk/search/Azure.Search.Documents/CHANGELOG.md +++ b/sdk/search/Azure.Search.Documents/CHANGELOG.md @@ -6,6 +6,7 @@ - Moved models for managing indexes, indexers, and skillsets to `Azure.Search.Documents.Indexes.Models`. - Split `SearchServiceClient` into `SearchIndexClient` for managing indexes, and `SearchIndexerClient` for managing indexers, both of which are now in `Azure.Search.Documents.Indexes`. +- Renamed `AnalyzeRequest` to `AnalyzeTextRequest`. - Renamed `SearchIndexerDataSource` to `SearchIndexerDataSourceConnection`. - Renamed methods on `SearchIndexerClient` matching "\*DataSource" to "\*DataSourceConnection". - Made collection- and dictionary-type properties read-only, i.e. has only get-accessors, based on [.NET Guidelines][net-guidelines-collection-properties]. diff --git a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs index 6fd9a6cb48f3b..7ec2d5cf81b54 100644 --- a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs +++ b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs @@ -109,8 +109,8 @@ public SearchIndexClient(System.Uri endpoint, Azure.AzureKeyCredential credentia public SearchIndexClient(System.Uri endpoint, Azure.AzureKeyCredential credential, Azure.Search.Documents.SearchClientOptions options) { } public virtual System.Uri Endpoint { get { throw null; } } public virtual string ServiceName { get { throw null; } } - public virtual Azure.Response> AnalyzeText(string indexName, Azure.Search.Documents.Indexes.Models.AnalyzeRequest analyzeRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> AnalyzeTextAsync(string indexName, Azure.Search.Documents.Indexes.Models.AnalyzeRequest analyzeRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> AnalyzeText(string indexName, Azure.Search.Documents.Indexes.Models.AnalyzeTextRequest request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> AnalyzeTextAsync(string indexName, Azure.Search.Documents.Indexes.Models.AnalyzeTextRequest request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateIndex(Azure.Search.Documents.Indexes.Models.SearchIndex index, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateIndexAsync(Azure.Search.Documents.Indexes.Models.SearchIndex index, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateOrUpdateIndex(Azure.Search.Documents.Indexes.Models.SearchIndex index, bool allowIndexDowntime = false, bool onlyIfUnchanged = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -212,9 +212,9 @@ internal AnalyzedTokenInfo() { } public int StartOffset { get { throw null; } } public string Token { get { throw null; } } } - public partial class AnalyzeRequest + public partial class AnalyzeTextRequest { - public AnalyzeRequest(string text) { } + public AnalyzeTextRequest(string text) { } public Azure.Search.Documents.Indexes.Models.LexicalAnalyzerName? Analyzer { get { throw null; } set { } } public System.Collections.Generic.IList CharFilters { get { throw null; } } public string Text { get { throw null; } } diff --git a/sdk/search/Azure.Search.Documents/src/Generated/IndexesRestClient.cs b/sdk/search/Azure.Search.Documents/src/Generated/IndexesRestClient.cs index d043fa369afde..e7cfecd40f0df 100644 --- a/sdk/search/Azure.Search.Documents/src/Generated/IndexesRestClient.cs +++ b/sdk/search/Azure.Search.Documents/src/Generated/IndexesRestClient.cs @@ -584,7 +584,7 @@ public Response GetStatistics(string indexName, Cancellat } } - internal HttpMessage CreateAnalyzeRequest(string indexName, AnalyzeRequest request) + internal HttpMessage CreateAnalyzeRequest(string indexName, AnalyzeTextRequest request) { var message = _pipeline.CreateMessage(); var request0 = message.Request; @@ -612,7 +612,7 @@ internal HttpMessage CreateAnalyzeRequest(string indexName, AnalyzeRequest reque /// The name of the index for which to test an analyzer. /// The text and analyzer or analysis components to test. /// The cancellation token to use. - public async Task> AnalyzeAsync(string indexName, AnalyzeRequest request, CancellationToken cancellationToken = default) + public async Task> AnalyzeAsync(string indexName, AnalyzeTextRequest request, CancellationToken cancellationToken = default) { if (indexName == null) { @@ -650,7 +650,7 @@ public async Task> AnalyzeAsync(string indexName, Analyz /// The name of the index for which to test an analyzer. /// The text and analyzer or analysis components to test. /// The cancellation token to use. - public Response Analyze(string indexName, AnalyzeRequest request, CancellationToken cancellationToken = default) + public Response Analyze(string indexName, AnalyzeTextRequest request, CancellationToken cancellationToken = default) { if (indexName == null) { diff --git a/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeRequest.Serialization.cs b/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeTextRequest.Serialization.cs similarity index 95% rename from sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeRequest.Serialization.cs rename to sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeTextRequest.Serialization.cs index a5943ff2a735c..ecccc0c38ddad 100644 --- a/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeRequest.Serialization.cs +++ b/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeTextRequest.Serialization.cs @@ -11,7 +11,7 @@ namespace Azure.Search.Documents.Indexes.Models { - public partial class AnalyzeRequest : IUtf8JsonSerializable + public partial class AnalyzeTextRequest : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeRequest.cs b/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeTextRequest.cs similarity index 74% rename from sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeRequest.cs rename to sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeTextRequest.cs index 56ad05a5cfa41..966afdad32c14 100644 --- a/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeRequest.cs +++ b/sdk/search/Azure.Search.Documents/src/Generated/Models/AnalyzeTextRequest.cs @@ -11,29 +11,16 @@ namespace Azure.Search.Documents.Indexes.Models { /// Specifies some text and analysis components used to break that text into tokens. - public partial class AnalyzeRequest + public partial class AnalyzeTextRequest { - /// Initializes a new instance of AnalyzeRequest. - /// The text to break into tokens. - public AnalyzeRequest(string text) - { - if (text == null) - { - throw new ArgumentNullException(nameof(text)); - } - - Text = text; - TokenFilters = new List(); - CharFilters = new List(); - } - /// Initializes a new instance of AnalyzeRequest. + /// Initializes a new instance of AnalyzeTextRequest. /// The text to break into tokens. /// The name of the analyzer to use to break the given text. If this parameter is not specified, you must specify a tokenizer instead. The tokenizer and analyzer parameters are mutually exclusive. /// The name of the tokenizer to use to break the given text. If this parameter is not specified, you must specify an analyzer instead. The tokenizer and analyzer parameters are mutually exclusive. /// An optional list of token filters to use when breaking the given text. This parameter can only be set when using the tokenizer parameter. /// An optional list of character filters to use when breaking the given text. This parameter can only be set when using the tokenizer parameter. - internal AnalyzeRequest(string text, LexicalAnalyzerName? analyzer, LexicalTokenizerName? tokenizer, IList tokenFilters, IList charFilters) + internal AnalyzeTextRequest(string text, LexicalAnalyzerName? analyzer, LexicalTokenizerName? tokenizer, IList tokenFilters, IList charFilters) { Text = text; Analyzer = analyzer; diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/Models/AnalyzeRequest.cs b/sdk/search/Azure.Search.Documents/src/Indexes/Models/AnalyzeTextRequest.cs similarity index 57% rename from sdk/search/Azure.Search.Documents/src/Indexes/Models/AnalyzeRequest.cs rename to sdk/search/Azure.Search.Documents/src/Indexes/Models/AnalyzeTextRequest.cs index 1b9f1bc3eead5..88d338ef33e91 100644 --- a/sdk/search/Azure.Search.Documents/src/Indexes/Models/AnalyzeRequest.cs +++ b/sdk/search/Azure.Search.Documents/src/Indexes/Models/AnalyzeTextRequest.cs @@ -1,13 +1,28 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Collections.Generic; using Azure.Core; namespace Azure.Search.Documents.Indexes.Models { - public partial class AnalyzeRequest + [CodeGenModel("AnalyzeRequest")] + public partial class AnalyzeTextRequest { + /// + /// Initializes a new instance of AnalyzeRequest. + /// One of or is also required. + /// + /// Required text to break into tokens. + public AnalyzeTextRequest(string text) + { + Text = text ?? throw new ArgumentNullException(nameof(text)); + + TokenFilters = new List(); + CharFilters = new List(); + } + /// An optional list of token filters to use when breaking the given text. This parameter can only be set when using the tokenizer parameter. [CodeGenMember(EmptyAsUndefined = true, Initialize = true)] public IList TokenFilters { get; } diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs index bbd0ce054faea..d3b27385204cd 100644 --- a/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs @@ -227,16 +227,16 @@ public virtual async Task> GetServiceStatistic /// Shows how an analyzer breaks text into tokens. /// /// The name of the index used to test an analyzer. - /// The containing the text and analyzer or analyzer components to test. + /// The containing the text and analyzer or analyzer components to test. /// Optional to propagate notifications that the operation should be canceled. /// /// The from the server containing a list of for analyzed text. /// - /// Thrown when or is null. + /// Thrown when or is null. /// Thrown when a failure is returned by the Search service. public virtual Response> AnalyzeText( string indexName, - AnalyzeRequest analyzeRequest, + AnalyzeTextRequest request, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeText)}"); @@ -245,7 +245,7 @@ public virtual Response> AnalyzeText( { Response result = IndexesClient.Analyze( indexName, - analyzeRequest, + request, cancellationToken); return Response.FromValue(result.Value.Tokens, result.GetRawResponse()); @@ -261,16 +261,16 @@ public virtual Response> AnalyzeText( /// Shows how an analyzer breaks text into tokens. /// /// The name of the index used to test an analyzer. - /// The containing the text and analyzer or analyzer components to test. + /// The containing the text and analyzer or analyzer components to test. /// Optional to propagate notifications that the operation should be canceled. /// /// The from the server containing a list of for analyzed text. /// - /// Thrown when or is null. + /// Thrown when or is null. /// Thrown when a failure is returned by the Search service. public virtual async Task>> AnalyzeTextAsync( string indexName, - AnalyzeRequest analyzeRequest, + AnalyzeTextRequest request, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeText)}"); @@ -279,7 +279,7 @@ public virtual async Task>> AnalyzeTex { Response result = await IndexesClient.AnalyzeAsync( indexName, - analyzeRequest, + request, cancellationToken) .ConfigureAwait(false); diff --git a/sdk/search/Azure.Search.Documents/tests/Models/AnalyzeTextRequestTests.cs b/sdk/search/Azure.Search.Documents/tests/Models/AnalyzeTextRequestTests.cs new file mode 100644 index 0000000000000..f9b908217d6af --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/Models/AnalyzeTextRequestTests.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Search.Documents.Indexes.Models; +using NUnit.Framework; + +namespace Azure.Search.Documents.Tests.Models +{ + public class AnalyzeTextRequestTests + { + [Test] + public void RequiresText() + { + ArgumentNullException ex = Assert.Throws(() => new AnalyzeTextRequest(null)); + Assert.AreEqual("text", ex.ParamName); + } + } +} diff --git a/sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs b/sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs index f492c83749213..2dfacaa06bf2a 100644 --- a/sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs +++ b/sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Threading.Tasks; using Azure.Core; @@ -314,5 +315,23 @@ await client.CreateOrUpdateSynonymMapAsync( await client.DeleteSynonymMapAsync(updatedMap, onlyIfUnchanged: true); } + + [Test] + public async Task AnalyzeText() + { + await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); + + SearchIndexClient client = resources.GetIndexClient(); + + AnalyzeTextRequest request = new AnalyzeTextRequest("The quick brown fox jumped over the lazy dog.") + { + Tokenizer = LexicalTokenizerName.Whitespace, + }; + + Response> result = await client.AnalyzeTextAsync(resources.IndexName, request); + IReadOnlyList tokens = result.Value; + + Assert.AreEqual(new[] { "The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog." }, tokens.Select(t => t.Token)); + } } } diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/AnalyzeText.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/AnalyzeText.json new file mode 100644 index 0000000000000..883af27c73f5f --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/AnalyzeText.json @@ -0,0 +1,106 @@ +{ + "Entries": [ + { + "RequestUri": "https://azs-net-heathsrchtst.search.windows.net/indexes(\u0027omcjubbl\u0027)/search.analyze?api-version=2019-05-06-Preview", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json; odata.metadata=minimal", + "api-key": "Sanitized", + "Content-Length": "81", + "Content-Type": "application/json", + "traceparent": "00-0fcda9bf5af6cc4ab507afc2cde9ff76-d9390cf074ea274c-00", + "User-Agent": [ + "azsdk-net-Search.Documents/1.0.0-dev.20200603.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "b6bb294210d3599c5ce1600661618eab", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "text": "The quick brown fox jumped over the lazy dog.", + "tokenizer": "whitespace" + }, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "client-request-id": "b6bb2942-10d3-599c-5ce1-600661618eab", + "Content-Length": "701", + "Content-Type": "application/json; odata.metadata=minimal", + "Date": "Thu, 04 Jun 2020 02:02:51 GMT", + "elapsed-time": "41", + "Expires": "-1", + "OData-Version": "4.0", + "Pragma": "no-cache", + "Preference-Applied": "odata.include-annotations=\u0022*\u0022", + "request-id": "b6bb2942-10d3-599c-5ce1-600661618eab", + "Strict-Transport-Security": "max-age=15724800; includeSubDomains", + "x-ms-client-request-id": "b6bb2942-10d3-599c-5ce1-600661618eab" + }, + "ResponseBody": { + "@odata.context": "https://azs-net-heathsrchtst.search.windows.net/$metadata#Microsoft.Azure.Search.V2019_05_06_Preview.AnalyzeResult", + "tokens": [ + { + "token": "The", + "startOffset": 0, + "endOffset": 3, + "position": 0 + }, + { + "token": "quick", + "startOffset": 4, + "endOffset": 9, + "position": 1 + }, + { + "token": "brown", + "startOffset": 10, + "endOffset": 15, + "position": 2 + }, + { + "token": "fox", + "startOffset": 16, + "endOffset": 19, + "position": 3 + }, + { + "token": "jumped", + "startOffset": 20, + "endOffset": 26, + "position": 4 + }, + { + "token": "over", + "startOffset": 27, + "endOffset": 31, + "position": 5 + }, + { + "token": "the", + "startOffset": 32, + "endOffset": 35, + "position": 6 + }, + { + "token": "lazy", + "startOffset": 36, + "endOffset": 40, + "position": 7 + }, + { + "token": "dog.", + "startOffset": 41, + "endOffset": 45, + "position": 8 + } + ] + } + } + ], + "Variables": { + "RandomSeed": "398631221", + "SearchIndexName": "omcjubbl", + "SEARCH_ADMIN_API_KEY": "Sanitized", + "SEARCH_SERVICE_NAME": "azs-net-heathsrchtst" + } +} \ No newline at end of file diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/AnalyzeTextAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/AnalyzeTextAsync.json new file mode 100644 index 0000000000000..68fb02aab69bc --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/AnalyzeTextAsync.json @@ -0,0 +1,106 @@ +{ + "Entries": [ + { + "RequestUri": "https://azs-net-heathsrchtst.search.windows.net/indexes(\u0027omcjubbl\u0027)/search.analyze?api-version=2019-05-06-Preview", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json; odata.metadata=minimal", + "api-key": "Sanitized", + "Content-Length": "81", + "Content-Type": "application/json", + "traceparent": "00-2814f435f4dcd24e9d2ab4ee73d60e28-90ec2e1c86b12949-00", + "User-Agent": [ + "azsdk-net-Search.Documents/1.0.0-dev.20200603.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "768227d217ad9009492ef7abdef00368", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "text": "The quick brown fox jumped over the lazy dog.", + "tokenizer": "whitespace" + }, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "client-request-id": "768227d2-17ad-9009-492e-f7abdef00368", + "Content-Length": "701", + "Content-Type": "application/json; odata.metadata=minimal", + "Date": "Thu, 04 Jun 2020 02:02:51 GMT", + "elapsed-time": "6", + "Expires": "-1", + "OData-Version": "4.0", + "Pragma": "no-cache", + "Preference-Applied": "odata.include-annotations=\u0022*\u0022", + "request-id": "768227d2-17ad-9009-492e-f7abdef00368", + "Strict-Transport-Security": "max-age=15724800; includeSubDomains", + "x-ms-client-request-id": "768227d2-17ad-9009-492e-f7abdef00368" + }, + "ResponseBody": { + "@odata.context": "https://azs-net-heathsrchtst.search.windows.net/$metadata#Microsoft.Azure.Search.V2019_05_06_Preview.AnalyzeResult", + "tokens": [ + { + "token": "The", + "startOffset": 0, + "endOffset": 3, + "position": 0 + }, + { + "token": "quick", + "startOffset": 4, + "endOffset": 9, + "position": 1 + }, + { + "token": "brown", + "startOffset": 10, + "endOffset": 15, + "position": 2 + }, + { + "token": "fox", + "startOffset": 16, + "endOffset": 19, + "position": 3 + }, + { + "token": "jumped", + "startOffset": 20, + "endOffset": 26, + "position": 4 + }, + { + "token": "over", + "startOffset": 27, + "endOffset": 31, + "position": 5 + }, + { + "token": "the", + "startOffset": 32, + "endOffset": 35, + "position": 6 + }, + { + "token": "lazy", + "startOffset": 36, + "endOffset": 40, + "position": 7 + }, + { + "token": "dog.", + "startOffset": 41, + "endOffset": 45, + "position": 8 + } + ] + } + } + ], + "Variables": { + "RandomSeed": "197061334", + "SearchIndexName": "omcjubbl", + "SEARCH_ADMIN_API_KEY": "Sanitized", + "SEARCH_SERVICE_NAME": "azs-net-heathsrchtst" + } +} \ No newline at end of file