Skip to content

Commit 3a62e55

Browse files
committed
Use new GetMappingSettings
1 parent a76f537 commit 3a62e55

File tree

2 files changed

+34
-44
lines changed

2 files changed

+34
-44
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageVersion Include="Elastic.Aspire.Hosting.Elasticsearch" Version="9.3.0" />
2626
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="9.1.0" />
2727
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
28-
<PackageVersion Include="Elastic.Ingest.Elasticsearch" Version="0.13.0" />
28+
<PackageVersion Include="Elastic.Ingest.Elasticsearch" Version="0.13.1" />
2929
<PackageVersion Include="InMemoryLogger" Version="1.0.66" />
3030
<PackageVersion Include="MartinCostello.Logging.XUnit.v3" Version="0.6.0" />
3131
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.4" />

src/tooling/Elastic.Documentation.Tooling/Exporters/ElasticsearchMarkdownExporter.cs

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Elastic.Documentation.Diagnostics;
99
using Elastic.Documentation.Search;
1010
using Elastic.Documentation.Serialization;
11-
using Elastic.Documentation.Site.Navigation;
1211
using Elastic.Ingest.Elasticsearch;
1312
using Elastic.Ingest.Elasticsearch.Catalog;
1413
using Elastic.Ingest.Elasticsearch.Semantic;
@@ -22,7 +21,7 @@
2221
namespace Elastic.Documentation.Tooling.Exporters;
2322

2423
public class ElasticsearchMarkdownExporter(ILoggerFactory logFactory, IDiagnosticsCollector collector, DocumentationEndpoints endpoints)
25-
: ElasticsearchMarkdownExporterBase<CatalogIndexChannelOptions<DocumentationDocument>, DocumentationCatalogIndexChannel>
24+
: ElasticsearchMarkdownExporterBase<CatalogIndexChannelOptions<DocumentationDocument>, CatalogIndexChannel<DocumentationDocument>>
2625
(logFactory, collector, endpoints)
2726
{
2827
/// <inheritdoc />
@@ -34,61 +33,26 @@ public class ElasticsearchMarkdownExporter(ILoggerFactory logFactory, IDiagnosti
3433
};
3534

3635
/// <inheritdoc />
37-
protected override DocumentationCatalogIndexChannel NewChannel(CatalogIndexChannelOptions<DocumentationDocument> options) => new(options);
36+
protected override CatalogIndexChannel<DocumentationDocument> NewChannel(CatalogIndexChannelOptions<DocumentationDocument> options) => new(options);
3837
}
3938

4039
public class ElasticsearchMarkdownSemanticExporter(ILoggerFactory logFactory, IDiagnosticsCollector collector, DocumentationEndpoints endpoints)
41-
: ElasticsearchMarkdownExporterBase<SemanticIndexChannelOptions<DocumentationDocument>, DocumentationSemanticIndexChannel>
40+
: ElasticsearchMarkdownExporterBase<SemanticIndexChannelOptions<DocumentationDocument>, SemanticIndexChannel<DocumentationDocument>>
4241
(logFactory, collector, endpoints)
4342
{
4443
/// <inheritdoc />
4544
protected override SemanticIndexChannelOptions<DocumentationDocument> NewOptions(DistributedTransport transport) => new(transport)
4645
{
4746
GetMapping = (inferenceId, _) => CreateMapping(inferenceId),
47+
GetMappingSetting = (_, _) => CreateMappingSetting(),
4848
IndexFormat = "semantic-documentation-{0:yyyy.MM.dd.HHmmss}",
4949
ActiveSearchAlias = "semantic-documentation",
5050
IndexNumThreads = IndexNumThreads,
5151
InferenceCreateTimeout = TimeSpan.FromMinutes(4)
5252
};
5353

5454
/// <inheritdoc />
55-
protected override DocumentationSemanticIndexChannel NewChannel(SemanticIndexChannelOptions<DocumentationDocument> options) => new(options);
56-
}
57-
58-
// Custom channel classes that override the settings
59-
public class DocumentationCatalogIndexChannel(CatalogIndexChannelOptions<DocumentationDocument> options) : CatalogIndexChannel<DocumentationDocument>(options)
60-
{
61-
protected override IReadOnlyDictionary<string, string> GetDefaultComponentIndexSettings()
62-
{
63-
var settings = new Dictionary<string, string>
64-
{
65-
["analysis.analyzer.default_search.tokenizer"] = "whitespace",
66-
["analysis.analyzer.default_search.filter.0"] = "lowercase",
67-
["analysis.analyzer.default_search.filter.1"] = "synonyms_filter",
68-
["analysis.filter.synonyms_filter.type"] = "synonym",
69-
["analysis.filter.synonyms_filter.synonyms_set"] = "docs",
70-
["analysis.filter.synonyms_filter.updateable"] = "true",
71-
};
72-
return settings;
73-
}
74-
}
75-
76-
public class DocumentationSemanticIndexChannel(SemanticIndexChannelOptions<DocumentationDocument> options)
77-
: SemanticIndexChannel<DocumentationDocument>(options)
78-
{
79-
protected override IReadOnlyDictionary<string, string> GetDefaultComponentIndexSettings()
80-
{
81-
var settings = new Dictionary<string, string>
82-
{
83-
["analysis.analyzer.default_search.tokenizer"] = "whitespace",
84-
["analysis.analyzer.default_search.filter.0"] = "lowercase",
85-
["analysis.analyzer.default_search.filter.1"] = "synonyms_filter",
86-
["analysis.filter.synonyms_filter.type"] = "synonym",
87-
["analysis.filter.synonyms_filter.synonyms_set"] = "docs",
88-
["analysis.filter.synonyms_filter.updateable"] = "true",
89-
};
90-
return settings;
91-
}
55+
protected override SemanticIndexChannel<DocumentationDocument> NewChannel(SemanticIndexChannelOptions<DocumentationDocument> options) => new(options);
9256
}
9357

9458
public abstract class ElasticsearchMarkdownExporterBase<TChannelOptions, TChannel>(
@@ -107,13 +71,39 @@ public abstract class ElasticsearchMarkdownExporterBase<TChannelOptions, TChanne
10771

10872
protected int IndexNumThreads => 8;
10973

74+
protected static string CreateMappingSetting() =>
75+
// language=json
76+
"""
77+
{
78+
"analysis": {
79+
"analyzer": {
80+
"synonyms_analyzer": {
81+
"tokenizer": "whitespace",
82+
"filter": [
83+
"lowercase",
84+
"synonyms_filter"
85+
]
86+
}
87+
},
88+
"filter": {
89+
"synonyms_filter": {
90+
"type": "synonym",
91+
"synonyms_set": "docs",
92+
"updateable": true
93+
}
94+
}
95+
}
96+
}
97+
""";
98+
11099
protected static string CreateMapping(string? inferenceId) =>
111100
// langugage=json
112101
$$"""
113102
{
114103
"properties": {
115104
"title": {
116105
"type": "text",
106+
"search_analyzer": "synonyms_analyzer",
117107
"fields": {
118108
"keyword": {
119109
"type": "keyword"
@@ -275,8 +265,8 @@ public async ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext,
275265
Description = fileContext.SourceFile.YamlFrontMatter?.Description,
276266

277267
Abstract = !string.IsNullOrEmpty(body)
278-
? body[..Math.Min(body.Length, 400)] + " " + string.Join(" \n- ", headings)
279-
: string.Empty,
268+
? body[..Math.Min(body.Length, 400)] + " " + string.Join(" \n- ", headings)
269+
: string.Empty,
280270
Applies = fileContext.SourceFile.YamlFrontMatter?.AppliesTo,
281271
UrlSegmentCount = url.Split('/', StringSplitOptions.RemoveEmptyEntries).Length,
282272
Parents = navigation.GetParentsOfMarkdownFile(file).Select(i => new ParentDocument

0 commit comments

Comments
 (0)