Skip to content

Commit 717d764

Browse files
authored
refactor(elasticsearch): autoComplete Support alwaysGetNewestElasticClient (#392)
* feat: AutoComplete SupportUpdate * refactor: Elasticsearch SupportUpdate * feat(Es): autoComplete Support alwaysGetNewestElasticClient * test: Modify unit tests * test: Modify unit tests * feat: Add Elasticsearch Client * feat(Caller): Caller supports synchronous calling asynchronous * test: Adjust unit test coverage
1 parent ed603cb commit 717d764

File tree

48 files changed

+881
-738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+881
-738
lines changed

src/BuildingBlocks/Caching/Masa.BuildingBlocks.Caching/TypeAlias/DefaultTypeAliasFactory.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public class DefaultTypeAliasFactory : MasaFactoryBase<ITypeAliasProvider, TypeA
1010

1111
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] TypeAlias, it was not found";
1212

13-
protected override MasaFactoryOptions<TypeAliasRelationOptions> FactoryOptions => _optionsMonitor.Value;
13+
protected override MasaFactoryOptions<TypeAliasRelationOptions> FactoryOptions => _options.CurrentValue;
1414

15-
private readonly IOptions<TypeAliasFactoryOptions> _optionsMonitor;
15+
private readonly IOptionsMonitor<TypeAliasFactoryOptions> _options;
1616

1717
public DefaultTypeAliasFactory(IServiceProvider serviceProvider) : base(serviceProvider)
1818
{
19-
_optionsMonitor = serviceProvider.GetRequiredService<IOptions<TypeAliasFactoryOptions>>();
19+
_options = serviceProvider.GetRequiredService<IOptionsMonitor<TypeAliasFactoryOptions>>();
2020
}
2121
}

src/BuildingBlocks/Data/Masa.BuildingBlocks.Data.Contracts/MasaFactoryBase.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public virtual TService Create()
2828
{
2929
var defaultOptions = GetDefaultOptions(FactoryOptions.Options);
3030
if (defaultOptions == null)
31-
throw new NotImplementedException(DefaultServiceNotFoundMessage);
31+
throw new NotSupportedException(DefaultServiceNotFoundMessage);
3232

3333
return defaultOptions.Func.Invoke(ServiceProvider);
3434
}
@@ -37,7 +37,7 @@ public virtual TService Create(string name)
3737
{
3838
var options = FactoryOptions.Options.SingleOrDefault(c => c.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
3939
if (options == null)
40-
throw new NotImplementedException(string.Format(SpecifyServiceNotFoundMessage, name));
40+
throw new NotSupportedException(string.Format(SpecifyServiceNotFoundMessage, name));
4141

4242
return options.Func.Invoke(ServiceProvider);
4343
}

src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/IdGenerator/DefaultIdGeneratorFactory.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public class DefaultIdGeneratorFactory : MasaFactoryBase<IIdGenerator, IdGenerat
2525
protected override string SpecifyServiceNotFoundMessage { get; } =
2626
"Please make sure you have used [{0}] IdGenerator, it was not found";
2727

28-
protected override MasaFactoryOptions<IdGeneratorRelationOptions> FactoryOptions => _optionsMonitor.CurrentValue;
28+
protected override MasaFactoryOptions<IdGeneratorRelationOptions> FactoryOptions => _options.CurrentValue;
2929

30-
private readonly IOptionsMonitor<IdGeneratorFactoryOptions> _optionsMonitor;
30+
private readonly IOptionsMonitor<IdGeneratorFactoryOptions> _options;
3131

3232
public DefaultIdGeneratorFactory(IServiceProvider serviceProvider) : base(serviceProvider)
3333
{
34-
_optionsMonitor = serviceProvider.GetRequiredService<IOptionsMonitor<IdGeneratorFactoryOptions>>();
34+
_options = serviceProvider.GetRequiredService<IOptionsMonitor<IdGeneratorFactoryOptions>>();
3535
}
3636

3737
public IIdGenerator<TOut> Create<TOut>() where TOut : notnull

src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/Serialization/DefaultDeserializerFactory.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ public class DefaultDeserializerFactory : MasaFactoryBase<IDeserializer, Deseria
99
protected override string DefaultServiceNotFoundMessage => "Default deserializer not found, you need to add it, like services.AddJson()";
1010

1111
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] deserializer, it was not found";
12-
protected override MasaFactoryOptions<DeserializerRelationOptions> FactoryOptions => _optionsMonitor.CurrentValue;
12+
protected override MasaFactoryOptions<DeserializerRelationOptions> FactoryOptions => _options.CurrentValue;
1313

14-
private readonly IOptionsMonitor<DeserializerFactoryOptions> _optionsMonitor;
14+
private readonly IOptionsMonitor<DeserializerFactoryOptions> _options;
1515

1616
public DefaultDeserializerFactory(IServiceProvider serviceProvider) : base(serviceProvider)
1717
{
18-
_optionsMonitor = serviceProvider.GetRequiredService<IOptionsMonitor<DeserializerFactoryOptions>>();
18+
_options = serviceProvider.GetRequiredService<IOptionsMonitor<DeserializerFactoryOptions>>();
1919
}
2020
}

src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/Serialization/DefaultSerializerFactory.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ public class DefaultSerializerFactory : MasaFactoryBase<ISerializer, SerializerR
99
protected override string DefaultServiceNotFoundMessage => "Default serializer not found, you need to add it, like services.AddJson()";
1010

1111
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] serializer, it was not found";
12-
protected override MasaFactoryOptions<SerializerRelationOptions> FactoryOptions => _optionsMonitor.CurrentValue;
12+
protected override MasaFactoryOptions<SerializerRelationOptions> FactoryOptions => _options.CurrentValue;
1313

14-
private readonly IOptionsMonitor<SerializerFactoryOptions> _optionsMonitor;
14+
private readonly IOptionsMonitor<SerializerFactoryOptions> _options;
1515

1616
public DefaultSerializerFactory(IServiceProvider serviceProvider) : base(serviceProvider)
1717
{
18-
_optionsMonitor = serviceProvider.GetRequiredService<IOptionsMonitor<SerializerFactoryOptions>>();
18+
_options = serviceProvider.GetRequiredService<IOptionsMonitor<SerializerFactoryOptions>>();
1919
}
2020
}

src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/TypeConverts/DefaultTypeConvertFactory.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ protected override string DefaultServiceNotFoundMessage
1111

1212
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] typeConvert, it was not found";
1313

14-
protected override MasaFactoryOptions<TypeConvertRelationOptions> FactoryOptions => _optionsMonitor.CurrentValue;
14+
protected override MasaFactoryOptions<TypeConvertRelationOptions> FactoryOptions => _options.CurrentValue;
1515

16-
private readonly IOptionsMonitor<TypeConvertFactoryOptions> _optionsMonitor;
16+
private readonly IOptionsMonitor<TypeConvertFactoryOptions> _options;
1717

1818
public DefaultTypeConvertFactory(IServiceProvider serviceProvider) : base(serviceProvider)
1919
{
20-
_optionsMonitor = serviceProvider.GetRequiredService<IOptionsMonitor<TypeConvertFactoryOptions>>();
20+
_options = serviceProvider.GetRequiredService<IOptionsMonitor<TypeConvertFactoryOptions>>();
2121
}
2222
}

src/BuildingBlocks/RulesEngine/Masa.BuildingBlocks.RulesEngine/DefaultRulesEngineFactory.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ protected override string DefaultServiceNotFoundMessage
1212
protected override string SpecifyServiceNotFoundMessage
1313
=> $"Please make sure you have used [{0}] {nameof(IRulesEngineClient)}, it was not found";
1414

15-
protected override MasaFactoryOptions<RulesEngineRelationOptions> FactoryOptions => _options.Value;
15+
protected override MasaFactoryOptions<RulesEngineRelationOptions> FactoryOptions => _options.CurrentValue;
1616

17-
private readonly IOptions<RulesEngineFactoryOptions> _options;
17+
private readonly IOptionsMonitor<RulesEngineFactoryOptions> _options;
1818

1919
public DefaultRulesEngineFactory(IServiceProvider serviceProvider) : base(serviceProvider)
2020
{
21-
_options = serviceProvider.GetRequiredService<IOptions<RulesEngineFactoryOptions>>();
21+
_options = serviceProvider.GetRequiredService<IOptionsMonitor<RulesEngineFactoryOptions>>();
2222
}
2323
}

src/BuildingBlocks/SearchEngine/Masa.BuildingBlocks.SearchEngine.AutoComplete/AutoCompleteClientBase.cs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ namespace Masa.BuildingBlocks.SearchEngine.AutoComplete;
55

66
public abstract class AutoCompleteClientBase : IAutoCompleteClient
77
{
8+
public abstract Task<bool> BuildAsync(CancellationToken cancellationToken = default);
9+
10+
public abstract Task RebuildAsync(CancellationToken cancellationToken = default);
11+
812
public virtual Task<GetResponse<AutoCompleteDocument<Guid>>> GetAsync(
913
string keyword,
1014
AutoCompleteOptions? options = null,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
// ReSharper disable once CheckNamespace
5+
6+
namespace Masa.BuildingBlocks.SearchEngine.AutoComplete;
7+
8+
public class AutoCompleteFactory : MasaFactoryBase<IAutoCompleteClient, AutoCompleteRelationsOptions>, IAutoCompleteFactory
9+
{
10+
protected override string DefaultServiceNotFoundMessage => "No default AutoComplete found";
11+
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] AutoComplete, it was not found";
12+
protected override MasaFactoryOptions<AutoCompleteRelationsOptions> FactoryOptions => _options.CurrentValue;
13+
14+
private readonly IOptionsMonitor<AutoCompleteFactoryOptions> _options;
15+
16+
public AutoCompleteFactory(IServiceProvider serviceProvider) : base(serviceProvider)
17+
{
18+
_options = serviceProvider.GetRequiredService<IOptionsMonitor<AutoCompleteFactoryOptions>>();
19+
}
20+
21+
public IAutoCompleteClient CreateClient() => base.Create();
22+
23+
public IAutoCompleteClient CreateClient(string name) => base.Create(name);
24+
}

src/BuildingBlocks/SearchEngine/Masa.BuildingBlocks.SearchEngine.AutoComplete/IAutoCompleteClient.cs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ namespace Masa.BuildingBlocks.SearchEngine.AutoComplete;
55

66
public interface IAutoCompleteClient
77
{
8+
Task<bool> BuildAsync(CancellationToken cancellationToken = default);
9+
10+
Task RebuildAsync(CancellationToken cancellationToken = default);
11+
812
Task<GetResponse<AutoCompleteDocument<Guid>>> GetAsync(
913
string keyword,
1014
AutoCompleteOptions? options = null,

src/BuildingBlocks/SearchEngine/Masa.BuildingBlocks.SearchEngine.AutoComplete/IAutoCompleteFactory.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
namespace Masa.BuildingBlocks.SearchEngine.AutoComplete;
55

6-
public interface IAutoCompleteFactory
6+
public interface IAutoCompleteFactory : IMasaFactory<IAutoCompleteClient>
77
{
8+
[Obsolete("Use Create() instead")]
89
IAutoCompleteClient CreateClient();
910

11+
[Obsolete("Use Create(name) instead")]
1012
IAutoCompleteClient CreateClient(string name);
1113
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
// ReSharper disable once CheckNamespace
5+
6+
namespace Masa.BuildingBlocks.SearchEngine.AutoComplete;
7+
8+
public class AutoCompleteFactoryOptions: MasaFactoryOptions<AutoCompleteRelationsOptions>
9+
{
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
// ReSharper disable once CheckNamespace
5+
6+
namespace Masa.BuildingBlocks.SearchEngine.AutoComplete;
7+
8+
public class AutoCompleteRelationsOptions : MasaRelationOptions<IAutoCompleteClient>
9+
{
10+
public AutoCompleteRelationsOptions(string name) : base(name)
11+
{
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

4+
global using Masa.BuildingBlocks.Data;
45
global using Masa.BuildingBlocks.SearchEngine.AutoComplete.Options;
56
global using Masa.BuildingBlocks.SearchEngine.AutoComplete.Response;
6-
7+
global using Microsoft.Extensions.DependencyInjection;
8+
global using Microsoft.Extensions.Options;

src/BuildingBlocks/SearchEngine/Tests/Masa.BuildingBlocks.SearchEngine.AutoComplete.Tests/CustomAutoCompleteClient.cs

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ namespace Masa.BuildingBlocks.SearchEngine.AutoComplete.Tests;
55

66
public class CustomAutoCompleteClient : AutoCompleteClientBase
77
{
8+
public override Task<bool> BuildAsync(CancellationToken cancellationToken = default)
9+
{
10+
throw new NotImplementedException();
11+
}
12+
13+
public override Task RebuildAsync(CancellationToken cancellationToken = default)
14+
{
15+
throw new NotImplementedException();
16+
}
17+
818
public override Task<GetResponse<TAudoCompleteDocument>> GetBySpecifyDocumentAsync<TAudoCompleteDocument>(string keyword, AutoCompleteOptions? options = null,
919
CancellationToken cancellationToken = default)
1020
{

0 commit comments

Comments
 (0)