6
6
using Elastic . Channels ;
7
7
using Elastic . Documentation . Configuration ;
8
8
using Elastic . Documentation . Diagnostics ;
9
+ using Elastic . Documentation . Extensions ;
9
10
using Elastic . Documentation . Search ;
10
11
using Elastic . Documentation . Serialization ;
11
12
using Elastic . Ingest . Elasticsearch ;
@@ -26,8 +27,9 @@ public class ElasticsearchMarkdownExporter(ILoggerFactory logFactory, IDiagnosti
26
27
/// <inheritdoc />
27
28
protected override CatalogIndexChannelOptions < DocumentationDocument > NewOptions ( DistributedTransport transport ) => new ( transport )
28
29
{
30
+ BulkOperationIdLookup = d => d . Url ,
29
31
GetMapping = ( ) => CreateMapping ( null ) ,
30
- GetMappingSettings = ( ) => CreateMappingSetting ( ) ,
32
+ GetMappingSettings = CreateMappingSetting ,
31
33
IndexFormat = $ "{ Endpoint . IndexNamePrefix . ToLowerInvariant ( ) } -{ indexNamespace . ToLowerInvariant ( ) } -{{0:yyyy.MM.dd.HHmmss}}",
32
34
ActiveSearchAlias = $ "{ Endpoint . IndexNamePrefix } -{ indexNamespace . ToLowerInvariant ( ) } ",
33
35
} ;
@@ -43,13 +45,14 @@ public class ElasticsearchMarkdownSemanticExporter(ILoggerFactory logFactory, ID
43
45
/// <inheritdoc />
44
46
protected override SemanticIndexChannelOptions < DocumentationDocument > NewOptions ( DistributedTransport transport ) => new ( transport )
45
47
{
48
+ BulkOperationIdLookup = d => d . Url ,
46
49
GetMapping = ( inferenceId , _ ) => CreateMapping ( inferenceId ) ,
47
50
GetMappingSettings = ( _ , _ ) => CreateMappingSetting ( ) ,
48
51
IndexFormat = $ "{ Endpoint . IndexNamePrefix . ToLowerInvariant ( ) } -{ indexNamespace . ToLowerInvariant ( ) } -{{0:yyyy.MM.dd.HHmmss}}",
49
52
ActiveSearchAlias = $ "{ Endpoint . IndexNamePrefix } -{ indexNamespace . ToLowerInvariant ( ) } ",
50
53
IndexNumThreads = Endpoint . IndexNumThreads ,
51
54
SearchNumThreads = Endpoint . SearchNumThreads ,
52
- InferenceCreateTimeout = TimeSpan . FromMinutes ( Endpoint . BootstrapTimeout ?? 4 )
55
+ InferenceCreateTimeout = TimeSpan . FromMinutes ( Endpoint . BootstrapTimeout ?? 4 ) ,
53
56
} ;
54
57
55
58
/// <inheritdoc />
@@ -86,14 +89,21 @@ protected static string CreateMappingSetting() =>
86
89
"lowercase",
87
90
"synonyms_filter"
88
91
]
89
- }
92
+ },
93
+ "hierarchy_analyzer": { "tokenizer": "path_tokenizer" }
90
94
},
91
95
"filter": {
92
96
"synonyms_filter": {
93
97
"type": "synonym",
94
98
"synonyms_set": "docs",
95
99
"updateable": true
96
100
}
101
+ },
102
+ "tokenizer": {
103
+ "path_tokenizer": {
104
+ "type": "path_hierarchy",
105
+ "delimiter": "/"
106
+ }
97
107
}
98
108
}
99
109
}
@@ -103,22 +113,22 @@ protected static string CreateMapping(string? inferenceId) =>
103
113
$$ """
104
114
{
105
115
"properties": {
106
- "title": {
107
- "type": "text",
108
- "search_analyzer": "synonyms_analyzer",
116
+ "url" : {
117
+ "type": "keyword",
109
118
"fields": {
110
- "keyword": {
111
- "type": "keyword"
112
- }
113
- {{ ( ! string . IsNullOrWhiteSpace ( inferenceId ) ? $$ """ , "semantic_text": {{{InferenceMapping(inferenceId)}}}""" : "" ) }}
119
+ "match": { "type": "text" },
120
+ "prefix": { "type": "text", "analyzer" : "hierarchy_analyzer" }
114
121
}
115
122
},
116
- "url": {
123
+ "hash" : { "type" : "keyword" },
124
+ "title": {
117
125
"type": "text",
126
+ "search_analyzer": "synonyms_analyzer",
118
127
"fields": {
119
128
"keyword": {
120
129
"type": "keyword"
121
130
}
131
+ {{ ( ! string . IsNullOrWhiteSpace ( inferenceId ) ? $$ """ , "semantic_text": {{{InferenceMapping(inferenceId)}}}""" : "" ) }}
122
132
}
123
133
},
124
134
"url_segment_count": {
@@ -275,24 +285,26 @@ public async ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext,
275
285
. Where ( text => ! string . IsNullOrEmpty ( text ) )
276
286
. ToArray ( ) ;
277
287
288
+ var @abstract = ! string . IsNullOrEmpty ( body )
289
+ ? body [ ..Math . Min ( body . Length , 400 ) ] + " " + string . Join ( " \n - " , headings )
290
+ : string . Empty ;
291
+
278
292
var doc = new DocumentationDocument
279
293
{
280
- Title = file . Title ,
281
294
Url = url ,
295
+ Hash = ShortId . Create ( url , body ) ,
296
+ Title = file . Title ,
282
297
Body = body ,
283
298
Description = fileContext . SourceFile . YamlFrontMatter ? . Description ,
284
-
285
- Abstract = ! string . IsNullOrEmpty ( body )
286
- ? body [ ..Math . Min ( body . Length , 400 ) ] + " " + string . Join ( " \n - " , headings )
287
- : string . Empty ,
299
+ Abstract = @abstract ,
288
300
Applies = fileContext . SourceFile . YamlFrontMatter ? . AppliesTo ,
289
301
UrlSegmentCount = url . Split ( '/' , StringSplitOptions . RemoveEmptyEntries ) . Length ,
290
302
Parents = navigation . GetParentsOfMarkdownFile ( file ) . Select ( i => new ParentDocument
291
303
{
292
304
Title = i . NavigationTitle ,
293
305
Url = i . Url
294
306
} ) . Reverse ( ) . ToArray ( ) ,
295
- Headings = headings
307
+ Headings = headings ,
296
308
} ;
297
309
return await TryWrite ( doc , ctx ) ;
298
310
}
0 commit comments