From 6f0527bca6e9ce58e7c50ec6f65f3c37ab5c61e0 Mon Sep 17 00:00:00 2001 From: "0298287677@mail.ru" <0298287677@mail.ru> Date: Fri, 4 Oct 2024 16:43:15 +0300 Subject: [PATCH 01/11] AddedFiltersSupport --- src/OrchardCore.Cms.Web/appsettings.json | 46 +- .../ElasticsearchOptionsExtensions.cs | 81 ++++ .../Startup.cs | 40 +- .../ElasticsearchOptions.cs | 2 + .../Services/ElasticIndexManager.cs | 432 +++++++++++++++++- 5 files changed, 553 insertions(+), 48 deletions(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs diff --git a/src/OrchardCore.Cms.Web/appsettings.json b/src/OrchardCore.Cms.Web/appsettings.json index 00b3945e8f0..2086cfe951a 100644 --- a/src/OrchardCore.Cms.Web/appsettings.json +++ b/src/OrchardCore.Cms.Web/appsettings.json @@ -182,16 +182,42 @@ // "EnableApiVersioningHeader": false //}, // Provides Elasticsearch Connection - //"OrchardCore_Elasticsearch": { - // "ConnectionType": "SingleNodeConnectionPool", - // "Url": "http://localhost", - // "Ports": [ 9200 ], - // "Username": "admin", - // "Password": "admin", - // "CloudId": "Orchard_Core_deployment:ZWFzdHVzMi5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo0NDMkNmMxZGQ4YzAzN2=", - // "CertificateFingerprint": "75:21:E7:92:8F:D5:7A:27:06:38:8E:A4:35:FE:F5:17:D7:37:F4:DF:F0:9A:D2:C0:C4:B6:FF:EE:D1:EA:2B:A7", - // "EnableApiVersioningHeader": false - //}, + "OrchardCore_Elasticsearch": { + "ConnectionType": "SingleNodeConnectionPool", + "Url": "http://localhost", + "Ports": [ 9200 ], + "Username": "admin", + "Password": "admin", + "CloudId": "Orchard_Core_deployment:ZWFzdHVzMi5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo0NDMkNmMxZGQ4YzAzN2=", + "CertificateFingerprint": "75:21:E7:92:8F:D5:7A:27:06:38:8E:A4:35:FE:F5:17:D7:37:F4:DF:F0:9A:D2:C0:C4:B6:FF:EE:D1:EA:2B:A7", + "EnableApiVersioningHeader": false, + "Analyzers": { + "standard": { + "type": "standard", + "filter": [ + "english_stop", + "search_synonym", + "my_stemmer" + ] + } + }, + "Filter": { + "english_stop": { + "type": "stop", + "stopwords": [ "_english_" ] + }, + "search_synonym": { + "type": "synonym", + "synonyms": [ + "bosch,бош" + ] + }, + "my_stemmer": { + "type": "stemmer", + "language": "light_german" + } + } + }, // WARNING: AutoSetup section given as an example for Development only, for Production use "Environment Variables" instead //"OrchardCore_AutoSetup": { // "AutoSetupPath": "", diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs new file mode 100644 index 00000000000..72a4c25aeeb --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs @@ -0,0 +1,81 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using Microsoft.Extensions.Configuration; +using OrchardCore.Environment.Shell.Configuration; + +namespace OrchardCore.Search.Elasticsearch.Extensions; +internal static class ElasticsearchOptionsExtensions +{ + internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions options, IConfigurationSection configuration) + { + var jsonNode = configuration.GetSection(nameof(options.Analyzers)).AsJsonNode(); + var jsonElement = JsonSerializer.Deserialize(jsonNode); + + var analyzersObject = JsonObject.Create(jsonElement, new JsonNodeOptions() + { + PropertyNameCaseInsensitive = true, + }); + + if (analyzersObject != null) + { + if (jsonNode is JsonObject jAnalyzers) + { + foreach (var analyzer in jAnalyzers) + { + if (analyzer.Value is not JsonObject jAnalyzer) + { + continue; + } + + options.Analyzers.Add(analyzer.Key, jAnalyzer); + } + } + } + + if (options.Analyzers.Count == 0) + { + // When no analyzers are configured, we'll define a default analyzer. + options.Analyzers.Add(ElasticsearchConstants.DefaultAnalyzer, new JsonObject + { + ["type"] = "standard", + }); + } + + return options; + } + + internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options, IConfigurationSection configuration) + { + var jsonNode = configuration.GetSection(nameof(options.Filter)).AsJsonNode(); + var jsonElement = JsonSerializer.Deserialize(jsonNode); + + var filterObject = JsonObject.Create(jsonElement, new JsonNodeOptions() + { + PropertyNameCaseInsensitive = true, + }); + + if (filterObject != null) + { + if (jsonNode is JsonObject jFilters) + { + foreach (var filter in jFilters) + { + if (filter.Value is not JsonObject jFilter) + { + continue; + } + + options.Filter.Add(filter.Key, jFilter); + } + } + } + + return options; + } + + internal static ElasticsearchOptions AddIndexPrefix(this ElasticsearchOptions options, IConfigurationSection configuration) + { + options.IndexPrefix = configuration.GetValue(nameof(options.IndexPrefix)); + return options; + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs index 6e71de34f8c..ec79e45f516 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs @@ -24,6 +24,7 @@ using OrchardCore.Search.Elasticsearch.Core.Providers; using OrchardCore.Search.Elasticsearch.Core.Services; using OrchardCore.Search.Elasticsearch.Drivers; +using OrchardCore.Search.Elasticsearch.Extensions; using OrchardCore.Search.Elasticsearch.Services; using OrchardCore.Search.Lucene.Handler; using OrchardCore.Security.Permissions; @@ -54,42 +55,9 @@ public override void ConfigureServices(IServiceCollection services) { var configuration = _shellConfiguration.GetSection(ElasticConnectionOptionsConfigurations.ConfigSectionName); - o.IndexPrefix = configuration.GetValue(nameof(o.IndexPrefix)); - - var jsonNode = configuration.GetSection(nameof(o.Analyzers)).AsJsonNode(); - var jsonElement = JsonSerializer.Deserialize(jsonNode); - - var analyzersObject = JsonObject.Create(jsonElement, new JsonNodeOptions() - { - PropertyNameCaseInsensitive = true, - }); - - if (analyzersObject != null) - { - o.IndexPrefix = configuration.GetValue(nameof(o.IndexPrefix)); - - if (jsonNode is JsonObject jAnalyzers) - { - foreach (var analyzer in jAnalyzers) - { - if (analyzer.Value is not JsonObject jAnalyzer) - { - continue; - } - - o.Analyzers.Add(analyzer.Key, jAnalyzer); - } - } - } - - if (o.Analyzers.Count == 0) - { - // When no analyzers are configured, we'll define a default analyzer. - o.Analyzers.Add(ElasticsearchConstants.DefaultAnalyzer, new JsonObject - { - ["type"] = "standard", - }); - } + o.AddIndexPrefix(configuration); + o.AddFilter(configuration); + o.AddAnalyzers(configuration); }); services.AddElasticServices(); diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Abstractions/ElasticsearchOptions.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Abstractions/ElasticsearchOptions.cs index 514d5cad837..53a6466ff40 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Abstractions/ElasticsearchOptions.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Abstractions/ElasticsearchOptions.cs @@ -7,4 +7,6 @@ public class ElasticsearchOptions public string IndexPrefix { get; set; } public Dictionary Analyzers { get; } = []; + + public Dictionary Filter { get; } = []; } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs index ad5b12d9f3c..f3ef55aa21e 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs @@ -41,6 +41,343 @@ public sealed class ElasticIndexManager { "custom", () => new CustomAnalyzer() }, { "stop", () => new StopAnalyzer() }, }; + + private List _tokenFilterNames = new List() + { + "asciifolding", + "common_grams", + "condition", + "delimited_payload", + "dictionary_decompounder", + "edge_ngram", + "elision", + "fingerprint", + "hunspell", + "hyphenation_decompounder", + "icu_collation", + "icu_folding", + "icu_normalizer", + "icu_transform", + "keep_types", + "keep", + "keyword_marker", + "kstem", + "kuromoji_part_of_speech", + "kuromoji_readingform", + "kuromoji_stemmer", + "length", + "limit", + "lowercase", + "multiplexer", + "ngram", + "nori_part_of_speech", + "pattern_capture", + "pattern_replace", + "phonetic", + "porter_stem", + "predicate_token_filter", + "remove_duplicates", + "reverse", + "shingle", + "snowball", + "stemmer_override", + "stemmer", + "stop", + "synonym_graph", + "synonym", + "trim", + "truncate", + "unique", + "uppercase", + "word_delimiter_graph", + "word_delimiter" + }; + private record TokenFilterBuildingInfo(ITokenFilter TokenFilter, Func AddTokenFilter); + private readonly Dictionary _tokenFilterBuildingInfoGetter = new(StringComparer.OrdinalIgnoreCase) + { + { + "asciifolding", + new TokenFilterBuildingInfo( new AsciiFoldingTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.AsciiFolding(name, f => (AsciiFoldingTokenFilter)tokenFilter) ) + }, + { + "common_grams", + new TokenFilterBuildingInfo( new CommonGramsTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.CommonGrams(name, f => (CommonGramsTokenFilter)tokenFilter) ) + }, + { + "condition", + new TokenFilterBuildingInfo( new ConditionTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Condition(name, f => (ConditionTokenFilter)tokenFilter) ) + }, + { + "delimited_payload", + new TokenFilterBuildingInfo( new DelimitedPayloadTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.DelimitedPayload(name, f => (DelimitedPayloadTokenFilter)tokenFilter) ) + }, + { + "dictionary_decompounder", + new TokenFilterBuildingInfo( new DictionaryDecompounderTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.DictionaryDecompounder(name, f => (DictionaryDecompounderTokenFilter)tokenFilter) ) + }, + { + "edge_ngram", + new TokenFilterBuildingInfo( new EdgeNGramTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.EdgeNGram(name, f => (EdgeNGramTokenFilter)tokenFilter) ) + }, + { + "elision", + new TokenFilterBuildingInfo( new ElisionTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Elision(name, f => (ElisionTokenFilter)tokenFilter) ) + }, + { + "fingerprint", + new TokenFilterBuildingInfo( new FingerprintTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Fingerprint(name, f => (FingerprintTokenFilter)tokenFilter) ) + }, + { + "hunspell", + new TokenFilterBuildingInfo( new HunspellTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Hunspell(name, f => (HunspellTokenFilter)tokenFilter) ) + }, + { + "hyphenation_decompounder", + new TokenFilterBuildingInfo( new HyphenationDecompounderTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.HyphenationDecompounder(name, f => (HyphenationDecompounderTokenFilter)tokenFilter) ) + }, + { + "icu_collation", + new TokenFilterBuildingInfo( new IcuCollationTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.IcuCollation(name, f => (IcuCollationTokenFilter)tokenFilter) ) + }, + { + "icu_folding", + new TokenFilterBuildingInfo( new IcuFoldingTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.IcuFolding(name, f => (IcuFoldingTokenFilter)tokenFilter) ) + }, + { + "icu_normalizer", + new TokenFilterBuildingInfo( new IcuNormalizationTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.IcuNormalization(name, f => (IcuNormalizationTokenFilter)tokenFilter) ) + }, + { + "icu_transform", + new TokenFilterBuildingInfo( new IcuTransformTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.IcuTransform(name, f => (IcuTransformTokenFilter)tokenFilter) ) + }, + { + "keep_types", + new TokenFilterBuildingInfo( new KeepTypesTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.KeepTypes(name, f => (KeepTypesTokenFilter)tokenFilter) ) + }, + { + "keep", + new TokenFilterBuildingInfo( new KeepWordsTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.KeepWords(name, f => (KeepWordsTokenFilter)tokenFilter) ) + }, + { + "keyword_marker", + new TokenFilterBuildingInfo( new KeywordMarkerTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.KeywordMarker(name, f => (KeywordMarkerTokenFilter)tokenFilter) ) + }, + { + "kstem", + new TokenFilterBuildingInfo( new KStemTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.KStem(name, f => (KStemTokenFilter)tokenFilter) ) + }, + { + "kuromoji_part_of_speech", + new TokenFilterBuildingInfo( new KuromojiPartOfSpeechTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.KuromojiPartOfSpeech(name, f => (KuromojiPartOfSpeechTokenFilter)tokenFilter) ) + }, + { + "kuromoji_readingform", + new TokenFilterBuildingInfo( new KuromojiReadingFormTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.KuromojiReadingForm(name, f => (KuromojiReadingFormTokenFilter)tokenFilter) ) + }, + { + "kuromoji_stemmer", + new TokenFilterBuildingInfo( new KuromojiStemmerTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.KuromojiStemmer(name, f => (KuromojiStemmerTokenFilter)tokenFilter) ) + }, + { + "length", + new TokenFilterBuildingInfo( new LengthTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Length(name, f => (LengthTokenFilter)tokenFilter) ) + }, + { + "limit", + new TokenFilterBuildingInfo( new LimitTokenCountTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.LimitTokenCount(name, f => (LimitTokenCountTokenFilter)tokenFilter) ) + }, + { + "lowercase", + new TokenFilterBuildingInfo( new LowercaseTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Lowercase(name, f => (LowercaseTokenFilter)tokenFilter) ) + }, + { + "multiplexer", + new TokenFilterBuildingInfo( new MultiplexerTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Multiplexer(name, f => (MultiplexerTokenFilter)tokenFilter) ) + }, + { + "ngram", + new TokenFilterBuildingInfo( new NGramTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.NGram(name, f => (NGramTokenFilter)tokenFilter) ) + }, + { + "nori_part_of_speech", + new TokenFilterBuildingInfo( new NoriPartOfSpeechTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.NoriPartOfSpeech(name, f => (NoriPartOfSpeechTokenFilter)tokenFilter) ) + }, + { + "pattern_capture", + new TokenFilterBuildingInfo( new PatternCaptureTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.PatternCapture(name, f => (PatternCaptureTokenFilter)tokenFilter) ) + }, + { + "pattern_replace", + new TokenFilterBuildingInfo( new PatternReplaceTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.PatternReplace(name, f => (PatternReplaceTokenFilter)tokenFilter) ) + }, + { + "phonetic", + new TokenFilterBuildingInfo( new PhoneticTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Phonetic(name, f => (PhoneticTokenFilter)tokenFilter) ) + }, + { + "porter_stem", + new TokenFilterBuildingInfo( new PorterStemTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.PorterStem(name, f => (PorterStemTokenFilter)tokenFilter) ) + }, + { + "predicate_token_filter", + new TokenFilterBuildingInfo( new PredicateTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Predicate(name, f => (PredicateTokenFilter)tokenFilter) ) + }, + { + "remove_duplicates", + new TokenFilterBuildingInfo( new RemoveDuplicatesTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.RemoveDuplicates(name, f => (RemoveDuplicatesTokenFilter)tokenFilter) ) + }, + { + "reverse", + new TokenFilterBuildingInfo( new ReverseTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Reverse(name, f => (ReverseTokenFilter)tokenFilter) ) + }, + { + "shingle", + new TokenFilterBuildingInfo( new ShingleTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Shingle(name, f => (ShingleTokenFilter)tokenFilter) ) + }, + { + "snowball", + new TokenFilterBuildingInfo( new SnowballTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Snowball(name, f => (SnowballTokenFilter)tokenFilter) ) + }, + { + "stemmer_override", + new TokenFilterBuildingInfo( new StemmerOverrideTokenFilterDescriptor(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.StemmerOverride(name, f => (StemmerOverrideTokenFilterDescriptor)tokenFilter) ) + }, + { + "stemmer", + new TokenFilterBuildingInfo( new StemmerTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Stemmer(name, f => (StemmerTokenFilter)tokenFilter) ) + }, + { + "stop", + new TokenFilterBuildingInfo( new StopTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Stop(name, f => (StopTokenFilter)tokenFilter) ) + }, + { + "synonym_graph", + new TokenFilterBuildingInfo( new SynonymGraphTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.SynonymGraph(name, f => (SynonymGraphTokenFilter)tokenFilter) ) + }, + { + "synonym", + new TokenFilterBuildingInfo( new SynonymTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Synonym(name, f => (SynonymTokenFilter)tokenFilter) ) + }, + { + "trim", + new TokenFilterBuildingInfo( new TrimTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Trim(name, f => (TrimTokenFilter)tokenFilter) ) + }, + { + "truncate", + new TokenFilterBuildingInfo( new TruncateTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Truncate(name, f => (TruncateTokenFilter)tokenFilter) ) + }, + { + "unique", + new TokenFilterBuildingInfo( new UniqueTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Unique(name, f => (UniqueTokenFilter)tokenFilter) ) + }, + { + "uppercase", + new TokenFilterBuildingInfo( new UppercaseTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.Uppercase(name, f => (UppercaseTokenFilter)tokenFilter) ) + }, + { + "word_delimiter_graph", + new TokenFilterBuildingInfo( new WordDelimiterGraphTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.WordDelimiterGraph(name, f => (WordDelimiterGraphTokenFilter)tokenFilter) ) + }, + { + "word_delimiter", + new TokenFilterBuildingInfo( new WordDelimiterTokenFilter(), + (TokenFiltersDescriptor d, ITokenFilter tokenFilter, string name) => + d.WordDelimiter(name, f => (WordDelimiterTokenFilter)tokenFilter) ) + } + }; private static readonly List _charsToRemove = [ '\\', @@ -101,8 +438,24 @@ public async Task CreateIndexAsync(ElasticIndexSettings elasticIndexSettin if (_elasticsearchOptions.Analyzers.TryGetValue(analyzerName, out var analyzerProperties)) { - var analyzer = CreateAnalyzer(analyzerProperties); - analysisDescriptor.Analyzers(a => a.UserDefined(analyzerName, analyzer)); + if (_elasticsearchOptions.Filter is not null) + { + var tokenFiltersDescriptor = GetTokenFilterDescriptor(_elasticsearchOptions.Filter); + analysisDescriptor.TokenFilters(f => tokenFiltersDescriptor); + } + + if (analyzerProperties.TryGetPropertyValue("filter", out var filterResult)) + { + var filterCollection = JsonSerializer.Deserialize>(filterResult); + + var existingFilters = filterCollection.Where(f => _tokenFilterNames.Contains(f)); + analysisDescriptor.Analyzers(a => a.Custom(analyzerName, c => c.Filters(existingFilters))); + } + else + { + var analyzer = CreateAnalyzer(analyzerProperties); + analysisDescriptor.Analyzers(a => a.UserDefined(analyzerName, analyzer)); + } indexSettingsDescriptor = new IndexSettingsDescriptor(); indexSettingsDescriptor.Analysis(an => analysisDescriptor); @@ -195,6 +548,81 @@ await _elasticClient.MapAsync(p => p return response.Acknowledged; } + private TokenFiltersDescriptor GetTokenFilterDescriptor(Dictionary filter) + { + var descriptor = new TokenFiltersDescriptor(); + + foreach (var filterName in filter.Keys) + { + var filterProps = filter[filterName]; + + if (filterProps.TryGetPropertyValue("type", out var typeObject) is false + || _tokenFilterBuildingInfoGetter.TryGetValue(typeObject.ToString(), out var tokenFilterBuildingInfo) is false) + { + continue; + } + + var properties = tokenFilterBuildingInfo.TokenFilter.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); + + foreach (var filterProperty in filterProps) + { + if (filterProperty.Value == null || string.Equals(filterProperty.Key, "type", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + var key = filterProperty.Key.Replace("_", string.Empty); + + var property = properties.FirstOrDefault(p => p.Name.Equals(key, StringComparison.OrdinalIgnoreCase)); + var propertyType = property.PropertyType; + + if (property == null) + { + continue; + } + + try + { + if (property.PropertyType == typeof(StopWords)) + { + if (filterProperty.Value is JsonArray) + { + var propertyValue = JsonSerializer.Deserialize>(filterProperty.Value); + + property.SetValue(tokenFilterBuildingInfo.TokenFilter, new StopWords(propertyValue)); + + tokenFilterBuildingInfo.AddTokenFilter(descriptor, tokenFilterBuildingInfo.TokenFilter, filterName); + _tokenFilterNames.Add(filterName); + } + + continue; + } + + if (filterProperty.Value is JsonArray jsonArray) + { + var propertyValue = JsonSerializer.Deserialize(filterProperty.Value, propertyType); + property.SetValue(tokenFilterBuildingInfo.TokenFilter, propertyValue); + } + else + { + var propertyValue = JsonSerializer.Deserialize(filterProperty.Value, propertyType); + property.SetValue(tokenFilterBuildingInfo.TokenFilter, propertyValue); + } + + tokenFilterBuildingInfo.AddTokenFilter(descriptor, tokenFilterBuildingInfo.TokenFilter, filterName); + _tokenFilterNames.Add(filterName); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + } + + return descriptor; + } + private IAnalyzer CreateAnalyzer(JsonObject analyzerProperties) { IAnalyzer analyzer = null; From b81ff24805daa8b039e9de250eb34722930b554c Mon Sep 17 00:00:00 2001 From: "0298287677@mail.ru" <0298287677@mail.ru> Date: Mon, 7 Oct 2024 15:30:32 +0300 Subject: [PATCH 02/11] Create default analyzers --- src/OrchardCore.Cms.Web/appsettings.json | 46 ++++--------------- .../Controllers/AdminController.cs | 7 ++- .../Services/ElasticIndexManager.cs | 38 +++++++++++++-- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/OrchardCore.Cms.Web/appsettings.json b/src/OrchardCore.Cms.Web/appsettings.json index 2086cfe951a..00b3945e8f0 100644 --- a/src/OrchardCore.Cms.Web/appsettings.json +++ b/src/OrchardCore.Cms.Web/appsettings.json @@ -182,42 +182,16 @@ // "EnableApiVersioningHeader": false //}, // Provides Elasticsearch Connection - "OrchardCore_Elasticsearch": { - "ConnectionType": "SingleNodeConnectionPool", - "Url": "http://localhost", - "Ports": [ 9200 ], - "Username": "admin", - "Password": "admin", - "CloudId": "Orchard_Core_deployment:ZWFzdHVzMi5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo0NDMkNmMxZGQ4YzAzN2=", - "CertificateFingerprint": "75:21:E7:92:8F:D5:7A:27:06:38:8E:A4:35:FE:F5:17:D7:37:F4:DF:F0:9A:D2:C0:C4:B6:FF:EE:D1:EA:2B:A7", - "EnableApiVersioningHeader": false, - "Analyzers": { - "standard": { - "type": "standard", - "filter": [ - "english_stop", - "search_synonym", - "my_stemmer" - ] - } - }, - "Filter": { - "english_stop": { - "type": "stop", - "stopwords": [ "_english_" ] - }, - "search_synonym": { - "type": "synonym", - "synonyms": [ - "bosch,бош" - ] - }, - "my_stemmer": { - "type": "stemmer", - "language": "light_german" - } - } - }, + //"OrchardCore_Elasticsearch": { + // "ConnectionType": "SingleNodeConnectionPool", + // "Url": "http://localhost", + // "Ports": [ 9200 ], + // "Username": "admin", + // "Password": "admin", + // "CloudId": "Orchard_Core_deployment:ZWFzdHVzMi5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo0NDMkNmMxZGQ4YzAzN2=", + // "CertificateFingerprint": "75:21:E7:92:8F:D5:7A:27:06:38:8E:A4:35:FE:F5:17:D7:37:F4:DF:F0:9A:D2:C0:C4:B6:FF:EE:D1:EA:2B:A7", + // "EnableApiVersioningHeader": false + //}, // WARNING: AutoSetup section given as an example for Development only, for Production use "Environment Variables" instead //"OrchardCore_AutoSetup": { // "AutoSetupPath": "", diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index 4203ebc0241..9f49213a5f4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -434,8 +434,11 @@ public async Task ForceDelete(ElasticIndexSettingsViewModel model) public async Task Mappings(string indexName) { - var mappings = await _elasticIndexManager.GetIndexMappings(indexName); - var formattedJson = JNode.Parse(mappings).ToJsonString(JOptions.Indented); + //var mappings = await _elasticIndexManager.GetIndexMappings(indexName); + //var settings = await _elasticIndexManager.GetIndexSettings(indexName); + var info = await _elasticIndexManager.GetIndexInfo(indexName); + + var formattedJson = JNode.Parse(info).ToJsonString(JOptions.Indented); return View(new MappingsViewModel { IndexName = _elasticIndexManager.GetFullIndexName(indexName), diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs index f3ef55aa21e..a794a72c376 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs @@ -449,7 +449,7 @@ public async Task CreateIndexAsync(ElasticIndexSettings elasticIndexSettin var filterCollection = JsonSerializer.Deserialize>(filterResult); var existingFilters = filterCollection.Where(f => _tokenFilterNames.Contains(f)); - analysisDescriptor.Analyzers(a => a.Custom(analyzerName, c => c.Filters(existingFilters))); + analysisDescriptor.Analyzers(a => a.Custom("default", c => c.Tokenizer("standard").Filters(existingFilters))); } else { @@ -588,12 +588,16 @@ private TokenFiltersDescriptor GetTokenFilterDescriptor(Dictionary>(filterProperty.Value); - property.SetValue(tokenFilterBuildingInfo.TokenFilter, new StopWords(propertyValue)); - - tokenFilterBuildingInfo.AddTokenFilter(descriptor, tokenFilterBuildingInfo.TokenFilter, filterName); - _tokenFilterNames.Add(filterName); } + else + { + var propertyValue = JsonSerializer.Deserialize(filterProperty.Value); + property.SetValue(tokenFilterBuildingInfo.TokenFilter, new StopWords(propertyValue)); + } + + tokenFilterBuildingInfo.AddTokenFilter(descriptor, tokenFilterBuildingInfo.TokenFilter, filterName); + _tokenFilterNames.Add(filterName); continue; } @@ -708,6 +712,30 @@ public async Task GetIndexMappings(string indexName) return response.Body; } + public async Task GetIndexSettings(string indexName) + { + var response = await _elasticClient.LowLevel.Indices.GetSettingsAsync(GetFullIndexName(indexName)); + + if (!response.Success) + { + _logger.LogWarning("There were issues retrieving index settings from Elasticsearch. {OriginalException}", response.OriginalException); + } + + return response.Body; + } + + public async Task GetIndexInfo(string indexName) + { + var response = await _elasticClient.LowLevel.Indices.GetAsync(GetFullIndexName(indexName)); + + if (!response.Success) + { + _logger.LogWarning("There were issues retrieving index info from Elasticsearch. {OriginalException}", response.OriginalException); + } + + return response.Body; + } + /// /// Store a last_task_id in the Elasticsearch index _meta mappings. /// This allows storing the last indexing task id executed on the Elasticsearch index. From 478002d6db45bfb29ad94546d0d1396b90fdc290 Mon Sep 17 00:00:00 2001 From: "0298287677@mail.ru" <0298287677@mail.ru> Date: Mon, 7 Oct 2024 18:15:35 +0300 Subject: [PATCH 03/11] Mappings renamed to Index info --- .../Controllers/AdminController.cs | 8 +++----- ...appingsViewModel.cs => IndexInfoViewModel.cs} | 4 ++-- .../Views/Admin/Index.cshtml | 2 +- .../Admin/{Mappings.cshtml => IndexInfo.cshtml} | 16 ++++++++-------- 4 files changed, 14 insertions(+), 16 deletions(-) rename src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/{MappingsViewModel.cs => IndexInfoViewModel.cs} (57%) rename src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/{Mappings.cshtml => IndexInfo.cshtml} (77%) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index 9f49213a5f4..87d1914c512 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -432,17 +432,15 @@ public async Task ForceDelete(ElasticIndexSettingsViewModel model) return RedirectToAction(nameof(Index)); } - public async Task Mappings(string indexName) + public async Task IndexInfo(string indexName) { - //var mappings = await _elasticIndexManager.GetIndexMappings(indexName); - //var settings = await _elasticIndexManager.GetIndexSettings(indexName); var info = await _elasticIndexManager.GetIndexInfo(indexName); var formattedJson = JNode.Parse(info).ToJsonString(JOptions.Indented); - return View(new MappingsViewModel + return View(new IndexInfoViewModel { IndexName = _elasticIndexManager.GetFullIndexName(indexName), - Mappings = formattedJson + IndexInfo = formattedJson }); } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/MappingsViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/IndexInfoViewModel.cs similarity index 57% rename from src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/MappingsViewModel.cs rename to src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/IndexInfoViewModel.cs index 0d350b911f0..e44fe18e8d5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/MappingsViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/IndexInfoViewModel.cs @@ -1,7 +1,7 @@ namespace OrchardCore.Search.Elasticsearch.ViewModels; -public class MappingsViewModel +public class IndexInfoViewModel { public string IndexName { get; set; } - public string Mappings { get; set; } + public string IndexInfo { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Index.cshtml b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Index.cshtml index 8a2ae27893e..84b5c64c2db 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Index.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Index.cshtml @@ -69,7 +69,7 @@

@entry.AnalyzerName

- @T["Mappings"] + @T["Index Info"] @T["Query"] @T["Reset"] @T["Rebuild"] diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Mappings.cshtml b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/IndexInfo.cshtml similarity index 77% rename from src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Mappings.cshtml rename to src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/IndexInfo.cshtml index 692698ce721..666caa53a27 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Mappings.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/IndexInfo.cshtml @@ -1,16 +1,16 @@ -@model MappingsViewModel +@model IndexInfoViewModel -

@T["Elasticsearch index mappings"]

+

@T["Elasticsearch index information"]

- +
-
+
- - @T["The Elasticsearch index mapping. For reference only."] + + @T["The Elasticsearch index information. For reference only."]
@@ -35,8 +35,8 @@ setTheme(); var modelUri = monaco.Uri.parse("x://orchardcore.search.elastic.mappings.json"); - var editor = document.getElementById('@Html.IdFor(x => x.Mappings)_editor'); - var textArea = document.getElementById('@Html.IdFor(x => x.Mappings)'); + var editor = document.getElementById('@Html.IdFor(x => x.IndexInfo)_editor'); + var textArea = document.getElementById('@Html.IdFor(x => x.IndexInfo)'); var schema = JSON.parse(editor.dataset.schema) var model = monaco.editor.createModel(textArea.value, "json", modelUri); From 8ccbf7eaaa9f9b8cdac4a2e1d5fb238f71abf5ac Mon Sep 17 00:00:00 2001 From: "0298287677@mail.ru" <0298287677@mail.ru> Date: Mon, 7 Oct 2024 21:07:50 +0300 Subject: [PATCH 04/11] TokenFilterBuildingInfo sealed --- .../Services/ElasticIndexManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs index a794a72c376..42314ee7a01 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexManager.cs @@ -92,7 +92,7 @@ public sealed class ElasticIndexManager "word_delimiter_graph", "word_delimiter" }; - private record TokenFilterBuildingInfo(ITokenFilter TokenFilter, Func AddTokenFilter); + private sealed record TokenFilterBuildingInfo(ITokenFilter TokenFilter, Func AddTokenFilter); private readonly Dictionary _tokenFilterBuildingInfoGetter = new(StringComparer.OrdinalIgnoreCase) { { From 31e63c586bed4d20ad54a306a09450ca553d733f Mon Sep 17 00:00:00 2001 From: Denis <95141776+denispetrische@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:12:09 +0300 Subject: [PATCH 05/11] Update src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs Co-authored-by: Hisham Bin Ateya --- .../Extensions/ElasticsearchOptionsExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs index 72a4c25aeeb..ba983ec93dd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs @@ -3,7 +3,8 @@ using Microsoft.Extensions.Configuration; using OrchardCore.Environment.Shell.Configuration; -namespace OrchardCore.Search.Elasticsearch.Extensions; +namespace OrchardCore.Search.Elasticsearch; + internal static class ElasticsearchOptionsExtensions { internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions options, IConfigurationSection configuration) From fa95b4892da9386e26e2546fb46eec6ba7e2d1f8 Mon Sep 17 00:00:00 2001 From: Denis <95141776+denispetrische@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:14:27 +0300 Subject: [PATCH 06/11] Update src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs Co-authored-by: Hisham Bin Ateya --- .../Extensions/ElasticsearchOptionsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs index ba983ec93dd..952d9d093df 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs @@ -17,7 +17,7 @@ internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions opti PropertyNameCaseInsensitive = true, }); - if (analyzersObject != null) + if (analyzersObject is not null) { if (jsonNode is JsonObject jAnalyzers) { From 3f632a744a3be324440a385c2e6b5de18a0d6e46 Mon Sep 17 00:00:00 2001 From: Denis <95141776+denispetrische@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:15:11 +0300 Subject: [PATCH 07/11] Update src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs Co-authored-by: Hisham Bin Ateya --- .../Extensions/ElasticsearchOptionsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs index 952d9d093df..0588dcc8df9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs @@ -38,7 +38,7 @@ internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions opti // When no analyzers are configured, we'll define a default analyzer. options.Analyzers.Add(ElasticsearchConstants.DefaultAnalyzer, new JsonObject { - ["type"] = "standard", + ["type"] = ElasticsearchConstants.DefaultAnalyzer, }); } From f8d82d33f3226a69ff567e3ca0f35a487204425d Mon Sep 17 00:00:00 2001 From: Denis <95141776+denispetrische@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:15:54 +0300 Subject: [PATCH 08/11] Update src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs Co-authored-by: Hisham Bin Ateya --- .../Extensions/ElasticsearchOptionsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs index 0588dcc8df9..cec43afbeaf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs @@ -55,7 +55,7 @@ internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options PropertyNameCaseInsensitive = true, }); - if (filterObject != null) + if (filterObject is not null) { if (jsonNode is JsonObject jFilters) { From 462224685f8251988cfa06868703db3a26aee7ac Mon Sep 17 00:00:00 2001 From: Denis <95141776+denispetrische@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:16:23 +0300 Subject: [PATCH 09/11] Update src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs Co-authored-by: Hisham Bin Ateya --- .../Extensions/ElasticsearchOptionsExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs index cec43afbeaf..577b81ea6ad 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs @@ -77,6 +77,7 @@ internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options internal static ElasticsearchOptions AddIndexPrefix(this ElasticsearchOptions options, IConfigurationSection configuration) { options.IndexPrefix = configuration.GetValue(nameof(options.IndexPrefix)); + return options; } } From 0edcd4c82c2534a15ecdfd57ee0d7c6cb7092b25 Mon Sep 17 00:00:00 2001 From: Denis <95141776+denispetrische@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:16:41 +0300 Subject: [PATCH 10/11] Update src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Search.Elasticsearch/Startup.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs index ec79e45f516..7210c30d264 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs @@ -24,7 +24,6 @@ using OrchardCore.Search.Elasticsearch.Core.Providers; using OrchardCore.Search.Elasticsearch.Core.Services; using OrchardCore.Search.Elasticsearch.Drivers; -using OrchardCore.Search.Elasticsearch.Extensions; using OrchardCore.Search.Elasticsearch.Services; using OrchardCore.Search.Lucene.Handler; using OrchardCore.Security.Permissions; From 465d88b9e416bb1eaaf917bd710164109f62bafa Mon Sep 17 00:00:00 2001 From: "0298287677@mail.ru" <0298287677@mail.ru> Date: Thu, 17 Oct 2024 08:20:03 +0300 Subject: [PATCH 11/11] Fixed codestyle ElasticsearchOptionsExtensions.cs --- .../Extensions/ElasticsearchOptionsExtensions.cs | 9 +++++---- .../OrchardCore.Search.Elasticsearch/Startup.cs | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs index 72a4c25aeeb..dbe990f1fe9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Configuration; using OrchardCore.Environment.Shell.Configuration; -namespace OrchardCore.Search.Elasticsearch.Extensions; +namespace OrchardCore.Search.Elasticsearch; internal static class ElasticsearchOptionsExtensions { internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions options, IConfigurationSection configuration) @@ -16,7 +16,7 @@ internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions opti PropertyNameCaseInsensitive = true, }); - if (analyzersObject != null) + if (analyzersObject is not null) { if (jsonNode is JsonObject jAnalyzers) { @@ -37,7 +37,7 @@ internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions opti // When no analyzers are configured, we'll define a default analyzer. options.Analyzers.Add(ElasticsearchConstants.DefaultAnalyzer, new JsonObject { - ["type"] = "standard", + ["type"] = ElasticsearchConstants.DefaultAnalyzer, }); } @@ -54,7 +54,7 @@ internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options PropertyNameCaseInsensitive = true, }); - if (filterObject != null) + if (filterObject is not null) { if (jsonNode is JsonObject jFilters) { @@ -76,6 +76,7 @@ internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options internal static ElasticsearchOptions AddIndexPrefix(this ElasticsearchOptions options, IConfigurationSection configuration) { options.IndexPrefix = configuration.GetValue(nameof(options.IndexPrefix)); + return options; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs index ec79e45f516..7210c30d264 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs @@ -24,7 +24,6 @@ using OrchardCore.Search.Elasticsearch.Core.Providers; using OrchardCore.Search.Elasticsearch.Core.Services; using OrchardCore.Search.Elasticsearch.Drivers; -using OrchardCore.Search.Elasticsearch.Extensions; using OrchardCore.Search.Elasticsearch.Services; using OrchardCore.Search.Lucene.Handler; using OrchardCore.Security.Permissions;