Skip to content
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

feat(autocomplete): support autocomplete #24

Merged
merged 9 commits into from
Mar 28, 2022
Prev Previous commit
Next Next commit
chore: adjust TryAddAutoCompleteRelation methods
zhenlei520 committed Mar 28, 2022
commit 29aee0ba11a91a0e46b2a6bbd9e3aca912e6ade3
Original file line number Diff line number Diff line change
@@ -51,15 +51,16 @@ private static void AddAutoCompleteCore<TDocument, TValue>(this IServiceCollecti
{
ArgumentNullException.ThrowIfNull(services);

string indexName = option.IndexName ?? throw new ArgumentNullException(nameof(option.IndexName));
ArgumentNullException.ThrowIfNull(option.IndexName,nameof(option.IndexName));

services.TryAddSingleton(new AutoCompleteRelationsOptions());

var autoCompleteRelations = new AutoCompleteRelations(elasticClient, client, indexName, option.Alias, option.IsDefault, option.DefaultOperator, option.DefaultSearchType);
var autoCompleteRelations = new AutoCompleteRelations(elasticClient, client, option.IndexName, option.Alias, option.IsDefault, option.DefaultOperator, option.DefaultSearchType);
services.TryAddAutoCompleteRelation(autoCompleteRelations);

services.TryAddSingleton<IAutoCompleteFactory, AutoCompleteFactory>();
services.TryAddSingleton(serviceProvider => serviceProvider.GetRequiredService<IAutoCompleteFactory>().CreateClient());
client.TryCreateIndexAsync(services.BuildServiceProvider().GetService<ILogger<IAutoCompleteClient>>(), indexName, option);
client.TryCreateIndexAsync(services.BuildServiceProvider().GetService<ILogger<IAutoCompleteClient>>(), option);
}

private static void TryAddAutoCompleteRelation(this IServiceCollection services, AutoCompleteRelations relation)
@@ -79,7 +80,6 @@ private static void TryAddAutoCompleteRelation(this IServiceCollection services,
private static void TryCreateIndexAsync<TDocument, TValue>(
this IMasaElasticClient client,
ILogger<IAutoCompleteClient>? logger,
string indexName,
AutoCompleteOptions<TDocument, TValue> option)
where TDocument : AutoCompleteDocument<TValue>
{
@@ -90,7 +90,7 @@ private static void TryCreateIndexAsync<TDocument, TValue>(
aliases.Add(option.Alias, new Alias());
}

var existsResponse = client.IndexExistAsync(indexName, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
var existsResponse = client.IndexExistAsync(option.IndexName, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
if (!existsResponse.IsValid || existsResponse.Exists)
{
if (!existsResponse.IsValid)
@@ -99,7 +99,7 @@ private static void TryCreateIndexAsync<TDocument, TValue>(
return;
}

client.CreateIndex(logger, indexName, aliases, option);
client.CreateIndex(logger, option.IndexName, aliases, option);
}

private static void CreateIndex<TDocument, TValue>(