Skip to content

Commit

Permalink
Rename AnalyzeResult to AnalyzeTextResult
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths committed Jun 4, 2020
1 parent ad21e16 commit 3a7a2ac
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 33 deletions.
1 change: 1 addition & 0 deletions sdk/search/Azure.Search.Documents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Indexes.Models.AnalyzedTokenInfo>> 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<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Indexes.Models.AnalyzedTokenInfo>>> AnalyzeTextAsync(string indexName, Azure.Search.Documents.Indexes.Models.AnalyzeRequest analyzeRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Indexes.Models.AnalyzedTokenInfo>> 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<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Indexes.Models.AnalyzedTokenInfo>>> AnalyzeTextAsync(string indexName, Azure.Search.Documents.Indexes.Models.AnalyzeTextRequest request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Search.Documents.Indexes.Models.SearchIndex> CreateIndex(Azure.Search.Documents.Indexes.Models.SearchIndex index, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Search.Documents.Indexes.Models.SearchIndex>> CreateIndexAsync(Azure.Search.Documents.Indexes.Models.SearchIndex index, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Search.Documents.Indexes.Models.SearchIndex> CreateOrUpdateIndex(Azure.Search.Documents.Indexes.Models.SearchIndex index, bool allowIndexDowntime = false, bool onlyIfUnchanged = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -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<string> CharFilters { get { throw null; } }
public string Text { get { throw null; } }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Initializes a new instance of AnalyzeRequest.
/// One of <see cref="Analyzer"/> or <see cref="Tokenizer"/> is also required.
/// </summary>
/// <param name="text">Required text to break into tokens.</param>
public AnalyzeTextRequest(string text)
{
Text = text ?? throw new ArgumentNullException(nameof(text));

TokenFilters = new List<TokenFilterName>();
CharFilters = new List<string>();
}

/// <summary> An optional list of token filters to use when breaking the given text. This parameter can only be set when using the tokenizer parameter. </summary>
[CodeGenMember(EmptyAsUndefined = true, Initialize = true)]
public IList<TokenFilterName> TokenFilters { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ public virtual async Task<Response<SearchServiceStatistics>> GetServiceStatistic
/// Shows how an analyzer breaks text into tokens.
/// </summary>
/// <param name="indexName">The name of the index used to test an analyzer.</param>
/// <param name="analyzeRequest">The <see cref="AnalyzeRequest"/> containing the text and analyzer or analyzer components to test.</param>
/// <param name="request">The <see cref="AnalyzeTextRequest"/> containing the text and analyzer or analyzer components to test.</param>
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the operation should be canceled.</param>
/// <returns>
/// The <see cref="Response{T}"/> from the server containing a list of <see cref="AnalyzedTokenInfo"/> for analyzed text.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> or <paramref name="analyzeRequest"/> is null.</exception>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> or <paramref name="request"/> is null.</exception>
/// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception>
public virtual Response<IReadOnlyList<AnalyzedTokenInfo>> AnalyzeText(
string indexName,
AnalyzeRequest analyzeRequest,
AnalyzeTextRequest request,
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeText)}");
Expand All @@ -245,7 +245,7 @@ public virtual Response<IReadOnlyList<AnalyzedTokenInfo>> AnalyzeText(
{
Response<AnalyzeResult> result = IndexesClient.Analyze(
indexName,
analyzeRequest,
request,
cancellationToken);

return Response.FromValue(result.Value.Tokens, result.GetRawResponse());
Expand All @@ -261,16 +261,16 @@ public virtual Response<IReadOnlyList<AnalyzedTokenInfo>> AnalyzeText(
/// Shows how an analyzer breaks text into tokens.
/// </summary>
/// <param name="indexName">The name of the index used to test an analyzer.</param>
/// <param name="analyzeRequest">The <see cref="AnalyzeRequest"/> containing the text and analyzer or analyzer components to test.</param>
/// <param name="request">The <see cref="AnalyzeTextRequest"/> containing the text and analyzer or analyzer components to test.</param>
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the operation should be canceled.</param>
/// <returns>
/// The <see cref="Response{T}"/> from the server containing a list of <see cref="AnalyzedTokenInfo"/> for analyzed text.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> or <paramref name="analyzeRequest"/> is null.</exception>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> or <paramref name="request"/> is null.</exception>
/// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception>
public virtual async Task<Response<IReadOnlyList<AnalyzedTokenInfo>>> AnalyzeTextAsync(
string indexName,
AnalyzeRequest analyzeRequest,
AnalyzeTextRequest request,
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeText)}");
Expand All @@ -279,7 +279,7 @@ public virtual async Task<Response<IReadOnlyList<AnalyzedTokenInfo>>> AnalyzeTex
{
Response<AnalyzeResult> result = await IndexesClient.AnalyzeAsync(
indexName,
analyzeRequest,
request,
cancellationToken)
.ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ArgumentNullException>(() => new AnalyzeTextRequest(null));
Assert.AreEqual("text", ex.ParamName);
}
}
}
19 changes: 19 additions & 0 deletions sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Azure.Core;
Expand Down Expand Up @@ -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<IReadOnlyList<AnalyzedTokenInfo>> result = await client.AnalyzeTextAsync(resources.IndexName, request);
IReadOnlyList<AnalyzedTokenInfo> tokens = result.Value;

Assert.AreEqual(new[] { "The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog." }, tokens.Select(t => t.Token));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3a7a2ac

Please sign in to comment.