- Notifications
You must be signed in to change notification settings - Fork 34
Support for analyzers #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Zyqsempai merged 13 commits into ArangoDB-Community:master from arangodb:feature-3.8/DE-201-support-for-analyzers Apr 28, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits Select commit Hold shift + click to select a range
0c7c625 Implemented 4 main analyzer endpoints
tjoubert 5578ef4 Coded all tests
tjoubert 28f848e Merge branch 'ArangoDB-Community:master' into feature-3.8/DE-201-supp…
tjoubert c6b84e0 Updated roadmap doc
tjoubert 7a163a4 Amended tests with new Trait Feature=Analyzer and filter out this fea…
tjoubert eaf4605 Changed test commands for ArangoDB 3.5 to skip Analyzer tests
tjoubert 5210791 Changed test commands for ArangoDB 3.6 to skip Analyzer tests
tjoubert 2ceb041 changes to config.yml
tjoubert 5bbb94a Fixed tests
tjoubert 0cd94f3 Enabled analyzers feature for v3.6
tjoubert 44df94e Added XML comments
tjoubert e240b98 Added test PostAnalyzerAsync_ShouldThrow_WhenAnalyzerIsInvalid
tjoubert 4bb9408 Merge branch 'ArangoDB-Community:master' into feature-3.8/DE-201-supp…
tjoubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions 152 arangodb-net-standard.Test/AnalyzerApi/AnalyzerApiClientTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Net; | ||
| using System.Threading.Tasks; | ||
| using ArangoDBNetStandard; | ||
| using ArangoDBNetStandard.AnalyzerApi; | ||
| using ArangoDBNetStandard.AnalyzerApi.Models; | ||
| using ArangoDBNetStandard.Transport; | ||
| using Moq; | ||
| using Xunit; | ||
| | ||
| namespace ArangoDBNetStandardTest.IndexApi | ||
| { | ||
| public class AnalyzerApiClientTest : IClassFixture<AnalyzerApiClientTestFixture>, IAsyncLifetime | ||
| { | ||
| private AnalyzerApiClient _analyzerApi; | ||
| private ArangoDBClient _adb; | ||
| | ||
| public AnalyzerApiClientTest(AnalyzerApiClientTestFixture fixture) | ||
| { | ||
| _adb = fixture.ArangoDBClient; | ||
| _analyzerApi = _adb.Analyzer; | ||
| } | ||
| | ||
| public Task InitializeAsync() | ||
| { | ||
| return Task.CompletedTask; | ||
| } | ||
| | ||
| public Task DisposeAsync() | ||
| { | ||
| return Task.CompletedTask; | ||
| } | ||
| | ||
| [Fact] | ||
| [Trait("Feature", "Analyzer")] | ||
| public async Task GetAllAnalyzersAsync_ShouldSucceed() | ||
| { | ||
| var res = await _analyzerApi.GetAllAnalyzersAsync(); | ||
| Assert.Equal(HttpStatusCode.OK, res.Code); | ||
| Assert.False(res.Error); | ||
| } | ||
| | ||
| [Fact] | ||
| [Trait("Feature", "Analyzer")] | ||
| public async Task PostAnalyzerAsync_ShouldSucceed() | ||
| { | ||
| var res = await _analyzerApi.PostAnalyzerAsync( | ||
| new Analyzer() | ||
| { | ||
| Name = "text_sc", | ||
| Type = "identity", | ||
| Properties = new AnalyzerProperties() | ||
| { | ||
| Accent = false, | ||
| Case = "lower", | ||
| Locale = "sc", | ||
| Stemming = false, | ||
| StopWords = new List<string>() | ||
| }, | ||
| Features = new List<string>() | ||
| { | ||
| "frequency", | ||
| "position", | ||
| "norm" | ||
| } | ||
| } | ||
| ); | ||
| Assert.NotNull(res); | ||
| Assert.NotNull(res.Name); | ||
| } | ||
| | ||
| [Fact] | ||
| [Trait("Feature", "Analyzer")] | ||
| public async Task PostAnalyzerAsync_ShouldThrow_WhenAnalyzerIsInvalid() | ||
| { | ||
| try | ||
| { | ||
| //This call should fail because... | ||
| var res = await _analyzerApi.PostAnalyzerAsync( | ||
| new Analyzer() | ||
| { | ||
| Name = "text_sc", | ||
| Type = "collection", //...invalid analyzer type | ||
| Properties = new AnalyzerProperties() | ||
| { | ||
| Accent = false, | ||
| Case = "lower", | ||
| Locale = "sc", | ||
| Stemming = false, | ||
| StopWords = new List<string>() | ||
| }, | ||
| Features = new List<string>() | ||
| { | ||
| "frequency", | ||
| "position", | ||
| "norm" | ||
| } | ||
| } | ||
| ); | ||
| } | ||
| catch (ApiErrorException ex) | ||
| { | ||
| Assert.NotNull(ex); | ||
| Assert.NotNull(ex.ApiError); | ||
| Assert.True(ex.ApiError.Error); | ||
| } | ||
| } | ||
| | ||
| [Fact] | ||
| [Trait("Feature", "Analyzer")] | ||
| public async Task GetAnalyzerAsync_ShouldSucceed() | ||
| { | ||
| var allRes = await _analyzerApi.GetAllAnalyzersAsync(); | ||
| var firstName = allRes.Result[0].Name; | ||
| var res = await _analyzerApi.GetAnalyzerAsync(firstName); | ||
| Assert.Equal(HttpStatusCode.OK, res.Code); | ||
| Assert.False(res.Error); | ||
| } | ||
| | ||
| [Fact] | ||
| [Trait("Feature", "Analyzer")] | ||
| public async Task DeleteAnalyzerAsync_ShouldSucceed() | ||
| { | ||
| var name = "text_mu"; | ||
| var createRes = await _analyzerApi.PostAnalyzerAsync( | ||
| new Analyzer() | ||
| { | ||
| Name = name, | ||
| Type = "identity", | ||
| Properties = new AnalyzerProperties() | ||
| { | ||
| Accent = false, | ||
| Case = "lower", | ||
| Locale = "mu", | ||
| Stemming = false, | ||
| StopWords = new List<string>() | ||
| }, | ||
| Features = new List<string>() | ||
| { | ||
| "frequency", | ||
| "position", | ||
| "norm" | ||
| } | ||
| } | ||
| ); | ||
| var res = await _analyzerApi.DeleteAnalyzerAsync(name); | ||
| Assert.Equal(HttpStatusCode.OK, res.Code); | ||
| Assert.False(res.Error); | ||
| } | ||
| } | ||
| } | ||
44 changes: 44 additions & 0 deletions 44 arangodb-net-standard.Test/AnalyzerApi/AnalyzerApiClientTestFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using ArangoDBNetStandard; | ||
| using ArangoDBNetStandard.CollectionApi.Models; | ||
| using ArangoDBNetStandard.AnalyzerApi.Models; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| | ||
| namespace ArangoDBNetStandardTest.IndexApi | ||
| { | ||
| public class AnalyzerApiClientTestFixture : ApiClientTestFixtureBase | ||
| { | ||
| public ArangoDBClient ArangoDBClient { get; internal set; } | ||
| | ||
| public AnalyzerApiClientTestFixture() | ||
| { | ||
| } | ||
| | ||
| public override async Task InitializeAsync() | ||
| { | ||
| await base.InitializeAsync(); | ||
| | ||
| Console.WriteLine("AnalyzerApiClientTestFixture.InitializeAsync() started."); | ||
| string dbName = nameof(AnalyzerApiClientTestFixture); | ||
| await CreateDatabase(dbName); | ||
| Console.WriteLine("Database " + dbName + " created successfully"); | ||
| ArangoDBClient = GetArangoDBClient(dbName); | ||
| try | ||
| { | ||
| var dbRes = await ArangoDBClient.Database.GetCurrentDatabaseInfoAsync(); | ||
| if (dbRes.Error) | ||
| throw new Exception("GetCurrentDatabaseInfoAsync failed: " + dbRes.Code.ToString()); | ||
| else | ||
| { | ||
| Console.WriteLine("In database " + dbRes.Result.Name); | ||
| } | ||
| } | ||
| catch (ApiErrorException ex) | ||
| { | ||
| Console.WriteLine(ex.Message); | ||
| throw ex; | ||
| } | ||
| | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| using System.Net; | ||
| using System.Threading.Tasks; | ||
| | ||
| using ArangoDBNetStandard.Serialization; | ||
| using ArangoDBNetStandard.Transport; | ||
| using ArangoDBNetStandard.AnalyzerApi.Models; | ||
| using System; | ||
| | ||
| namespace ArangoDBNetStandard.AnalyzerApi | ||
| { | ||
| /// <summary> | ||
| /// A client for interacting with ArangoDB Analyzer endpoints, | ||
| /// implementing <see cref="IAnalyzerApiClient"/>. | ||
| /// </summary> | ||
| public class AnalyzerApiClient : ApiClientBase, IAnalyzerApiClient | ||
| { | ||
| /// <summary> | ||
| /// The transport client used to communicate with the ArangoDB host. | ||
| /// </summary> | ||
| protected IApiClientTransport _client; | ||
| | ||
| /// <summary> | ||
| /// The root path of the API. | ||
| /// </summary> | ||
| protected readonly string _analyzerApiPath = "_api/analyzer"; | ||
| | ||
| /// <summary> | ||
| /// Creates an instance of <see cref="AnalyzerApiClient"/> | ||
| /// using the provided transport layer and the default JSON serialization. | ||
| /// </summary> | ||
| /// <param name="client">Transport client that the API client will use to communicate with ArangoDB</param> | ||
| public AnalyzerApiClient(IApiClientTransport client) | ||
| : base(new JsonNetApiClientSerialization()) | ||
| { | ||
| _client = client; | ||
| } | ||
| | ||
| /// <summary> | ||
| /// Creates an instance of <see cref="AnalyzerApiClient"/> | ||
| /// using the provided transport and serialization layers. | ||
| /// </summary> | ||
| /// <param name="client">Transport client that the API client will use to communicate with ArangoDB.</param> | ||
| /// <param name="serializer">Serializer to be used.</param> | ||
| public AnalyzerApiClient(IApiClientTransport client, IApiClientSerialization serializer) | ||
| : base(serializer) | ||
| { | ||
| _client = client; | ||
| } | ||
| | ||
| /// <summary> | ||
| /// Fetch the list of available Analyzer definitions. | ||
| /// GET /_api/analyzer | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public virtual async Task<GetAllAnalyzersResponse> GetAllAnalyzersAsync() | ||
| { | ||
| string uri = _analyzerApiPath; | ||
| using (var response = await _client.GetAsync(uri).ConfigureAwait(false)) | ||
| { | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); | ||
| return DeserializeJsonFromStream<GetAllAnalyzersResponse>(stream); | ||
| } | ||
| throw await GetApiErrorException(response).ConfigureAwait(false); | ||
| } | ||
| } | ||
| | ||
| /// <summary> | ||
| /// Creates a new Analyzer based on the provided definition | ||
| /// POST /_api/analyzer | ||
| /// </summary> | ||
| /// <param name="body">The properties of the new analyzer.</param> | ||
| /// <returns></returns> | ||
| public virtual async Task<Analyzer> PostAnalyzerAsync(Analyzer body) | ||
| { | ||
| if (body == null) | ||
| { | ||
| throw new ArgumentException("body is required", nameof(body)); | ||
| } | ||
| var uri = _analyzerApiPath; | ||
| var content = GetContent(body, new ApiClientSerializationOptions(true, true)); | ||
| using (var response = await _client.PostAsync(uri, content).ConfigureAwait(false)) | ||
| { | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); | ||
| return DeserializeJsonFromStream<Analyzer>(stream); | ||
| } | ||
| throw await GetApiErrorException(response).ConfigureAwait(false); | ||
| } | ||
| } | ||
| | ||
| /// <summary> | ||
| /// Fetches the definition of the specified analyzer. | ||
| /// GET /_api/analyzer/{analyzer-name} | ||
| /// </summary> | ||
| /// <param name="analyzerName">The name of the analyzer</param> | ||
| /// <returns></returns> | ||
| public virtual async Task<GetAnalyzerResponse> GetAnalyzerAsync(string analyzerName) | ||
| { | ||
| if (string.IsNullOrEmpty(analyzerName)) | ||
| { | ||
| throw new ArgumentException("Analyzer name is required", nameof(analyzerName)); | ||
| } | ||
| string uri = _analyzerApiPath + '/' + WebUtility.UrlEncode(analyzerName); | ||
| using (var response = await _client.GetAsync(uri).ConfigureAwait(false)) | ||
| { | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); | ||
| return DeserializeJsonFromStream<GetAnalyzerResponse>(stream); | ||
| } | ||
| throw await GetApiErrorException(response).ConfigureAwait(false); | ||
| } | ||
| } | ||
| | ||
| /// <summary> | ||
| /// Deletes an Analyzer. | ||
| /// DELETE /_api/analyzer/{analyzer-name} | ||
| /// </summary> | ||
| /// <param name="analyzerName">The name of the analyzer</param> | ||
| /// <returns></returns> | ||
| public virtual async Task<DeleteAnalyzerResponse> DeleteAnalyzerAsync(string analyzerName) | ||
| { | ||
| if (string.IsNullOrEmpty(analyzerName)) | ||
| { | ||
| throw new ArgumentException("Analyzer name is required", nameof(analyzerName)); | ||
| } | ||
| string uri = _analyzerApiPath + '/' + WebUtility.UrlEncode(analyzerName); | ||
| using (var response = await _client.DeleteAsync(uri).ConfigureAwait(false)) | ||
| { | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); | ||
| return DeserializeJsonFromStream<DeleteAnalyzerResponse>(stream); | ||
| } | ||
| throw await GetApiErrorException(response).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.