diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs index 6e71de34f8c..15fcdac8a0b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs @@ -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, }); } }); diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/ElasticsearchConstants.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/ElasticsearchConstants.cs index b2dd21d0748..e52d7b16dd7 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/ElasticsearchConstants.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/ElasticsearchConstants.cs @@ -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"; } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs index ad5b12d9f3c..36058d98ba7 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs @@ -31,15 +31,15 @@ public sealed class ElasticIndexManager private readonly string _lastTaskId = "last_task_id"; private readonly Dictionary> _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 _charsToRemove = [ @@ -97,7 +97,9 @@ public async Task 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)) {