Skip to content

Commit

Permalink
Use ElasticsearchConstants.DefaultAnalyzer when it's possible (#16896)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Oct 17, 2024
1 parent 7ede2ef commit acb97ca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override void ConfigureServices(IServiceCollection services)
// When no analyzers are configured, we'll define a default analyzer.
o.Analyzers.Add(ElasticsearchConstants.DefaultAnalyzer, new JsonObject
{
["type"] = "standard",
["type"] = ElasticsearchConstants.DefaultAnalyzer,
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@ namespace OrchardCore.Search.Elasticsearch;
public static class ElasticsearchConstants
{
public const string DefaultAnalyzer = "standard";

public const string SimpleAnalyzer = "simple";

public const string KeywordAnalyzer = "keyword";

public const string WhitespaceAnalyzer = "whitespace";

public const string PatternAnalyzer = "pattern";

public const string LanguageAnalyzer = "language";

public const string FingerprintAnalyzer = "fingerprint";

public const string CustomAnalyzer = "custom";

public const string StopAnalyzer = "stop";
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public sealed class ElasticIndexManager
private readonly string _lastTaskId = "last_task_id";
private readonly Dictionary<string, Func<IAnalyzer>> _analyzerGetter = new(StringComparer.OrdinalIgnoreCase)
{
{ "standard", () => new StandardAnalyzer() },
{ "simple", () => new SimpleAnalyzer() },
{ "keyword", () => new KeywordAnalyzer() },
{ "whitespace", () => new WhitespaceAnalyzer() },
{ "pattern", () => new PatternAnalyzer() },
{ "language", () => new LanguageAnalyzer() },
{ "fingerprint", () => new FingerprintAnalyzer() },
{ "custom", () => new CustomAnalyzer() },
{ "stop", () => new StopAnalyzer() },
{ ElasticsearchConstants.DefaultAnalyzer, () => new StandardAnalyzer() },
{ ElasticsearchConstants.SimpleAnalyzer, () => new SimpleAnalyzer() },
{ ElasticsearchConstants.KeywordAnalyzer, () => new KeywordAnalyzer() },
{ ElasticsearchConstants.WhitespaceAnalyzer, () => new WhitespaceAnalyzer() },
{ ElasticsearchConstants.PatternAnalyzer, () => new PatternAnalyzer() },
{ ElasticsearchConstants.LanguageAnalyzer, () => new LanguageAnalyzer() },
{ ElasticsearchConstants.FingerprintAnalyzer, () => new FingerprintAnalyzer() },
{ ElasticsearchConstants.CustomAnalyzer, () => new CustomAnalyzer() },
{ ElasticsearchConstants.StopAnalyzer, () => new StopAnalyzer() },
};
private static readonly List<char> _charsToRemove =
[
Expand Down Expand Up @@ -97,7 +97,9 @@ public async Task<bool> CreateIndexAsync(ElasticIndexSettings elasticIndexSettin
var indexSettingsDescriptor = new IndexSettingsDescriptor();

// The name "standardanalyzer" is a legacy used prior OC 1.6 release. It can be removed in future releases.
var analyzerName = (elasticIndexSettings.AnalyzerName == "standardanalyzer" ? null : elasticIndexSettings.AnalyzerName) ?? "standard";
var analyzerName = (elasticIndexSettings.AnalyzerName == "standardanalyzer"
? null
: elasticIndexSettings.AnalyzerName) ?? ElasticsearchConstants.DefaultAnalyzer;

if (_elasticsearchOptions.Analyzers.TryGetValue(analyzerName, out var analyzerProperties))
{
Expand Down

0 comments on commit acb97ca

Please sign in to comment.