Skip to content

Commit

Permalink
feat: moved stemmer to OpenSearchModuleOptions
Browse files Browse the repository at this point in the history
Refs: SITKO-CORE-T-18
  • Loading branch information
IgorAlymov committed Jul 17, 2024
1 parent c372e7b commit 1256fdb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenSearchModuleOptions>
Expand Down
6 changes: 3 additions & 3 deletions src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class OpenSearchSearcher<TSearchModel>(
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<bool> AddOrUpdateAsync(string indexName, IEnumerable<TSearchModel> searchModels,
CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -231,10 +231,10 @@ private static SearchDescriptor<TSearchModel> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestModelProvider>();
Expand Down

0 comments on commit 1256fdb

Please sign in to comment.