From 1256fdbcda8ec5b21feac55b3823c062dff6bf99 Mon Sep 17 00:00:00 2001 From: IgorAlymov Date: Wed, 17 Jul 2024 12:07:21 +0500 Subject: [PATCH] feat: moved stemmer to OpenSearchModuleOptions Refs: SITKO-CORE-T-18 --- src/Sitko.Core.Search.OpenSearch/OpenSearchModuleOptions.cs | 1 + src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs | 6 +++--- tests/Sitko.Core.Search.OpenSearch.Tests/OpenSearchTests.cs | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Sitko.Core.Search.OpenSearch/OpenSearchModuleOptions.cs b/src/Sitko.Core.Search.OpenSearch/OpenSearchModuleOptions.cs index b52d692b4..d66c991ff 100644 --- a/src/Sitko.Core.Search.OpenSearch/OpenSearchModuleOptions.cs +++ b/src/Sitko.Core.Search.OpenSearch/OpenSearchModuleOptions.cs @@ -10,6 +10,7 @@ public class OpenSearchModuleOptions : SearchModuleOptions public string Password { get; set; } = ""; public bool EnableClientLogging { get; set; } public bool DisableCertificatesValidation { get; set; } + public string CustomStemmer { get; set; } = ""; } public class OpenSearchModuleOptionsValidator : AbstractValidator diff --git a/src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs b/src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs index 0c8fbee21..86c8b1eb0 100644 --- a/src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs +++ b/src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs @@ -15,7 +15,7 @@ public class OpenSearchSearcher( private OpenSearchModuleOptions Options => optionsMonitor.CurrentValue; private OpenSearchClient? client; private const string CustomAnalyze = "custom_analyze"; - private const string RussianStemmer = "russian_stemmer"; + private const string StemmerName = "custom_stemmer"; public async Task AddOrUpdateAsync(string indexName, IEnumerable searchModels, CancellationToken cancellationToken = default) @@ -231,10 +231,10 @@ private static SearchDescriptor GetSearchRequest(SearchDescriptor< private AnalysisDescriptor CreateAnalysisDescriptor(AnalysisDescriptor a) => a.Analyzers(aa => aa.Custom(CustomAnalyze, ca => ca .Tokenizer("standard") - .Filters("lowercase", "stop", "snowball", RussianStemmer) + .Filters("lowercase", "stop", "snowball", StemmerName) ) ).TokenFilters(descriptor => - descriptor.Stemmer(RussianStemmer, filterDescriptor => filterDescriptor.Language("russian"))); + descriptor.Stemmer(StemmerName, filterDescriptor => filterDescriptor.Language(Options.CustomStemmer))); private CreateIndexDescriptor CreateIndexDescriptor(CreateIndexDescriptor createIndexDescriptor) => createIndexDescriptor.Settings(s => s.Analysis(CreateAnalysisDescriptor)) diff --git a/tests/Sitko.Core.Search.OpenSearch.Tests/OpenSearchTests.cs b/tests/Sitko.Core.Search.OpenSearch.Tests/OpenSearchTests.cs index 604f46bfb..fce3a2244 100644 --- a/tests/Sitko.Core.Search.OpenSearch.Tests/OpenSearchTests.cs +++ b/tests/Sitko.Core.Search.OpenSearch.Tests/OpenSearchTests.cs @@ -128,6 +128,7 @@ protected override IHostApplicationBuilder ConfigureApplication(IHostApplication moduleOptions.Password = hostBuilder.Configuration.GetSection("OpenSearchModuleOptions")["Password"]; moduleOptions.InitProviders = false; moduleOptions.DisableCertificatesValidation = true; + moduleOptions.CustomStemmer = "russian"; }); hostBuilder.Services.AddSingleton();