33// See the LICENSE file in the project root for more information
44
55using System . IO . Abstractions ;
6+ using Elastic . Documentation . AppliesTo ;
67using Elastic . Documentation . Configuration ;
78using Elastic . Documentation . Diagnostics ;
89using Elastic . Documentation . Search ;
@@ -82,17 +83,16 @@ public async ValueTask StartAsync(Cancel ctx = default)
8283 {
8384 _ = await _lexicalChannel . Channel . BootstrapElasticsearchAsync ( BootstrapMethod . Failure , null , ctx ) ;
8485
85- var semanticIndex = _semanticChannel . Channel . IndexName ;
8686 var semanticWriteAlias = string . Format ( _semanticChannel . Channel . Options . IndexFormat , "latest" ) ;
87- var semanticIndexHead = await _transport . HeadAsync ( semanticWriteAlias , ctx ) ;
88- if ( ! semanticIndexHead . ApiCallDetails . HasSuccessfulStatusCode )
87+ var semanticIndexAvailable = await _transport . HeadAsync ( semanticWriteAlias , ctx ) ;
88+ _ = await _semanticChannel . Channel . BootstrapElasticsearchAsync ( BootstrapMethod . Failure , null , ctx ) ;
89+ var semanticIndex = _semanticChannel . Channel . IndexName ;
90+ if ( ! semanticIndexAvailable . ApiCallDetails . HasSuccessfulStatusCode )
8991 {
90- _logger . LogInformation ( "No semantic index exists yet, creating index {Index} for semantic search" , semanticIndex ) ;
91- _ = await _semanticChannel . Channel . BootstrapElasticsearchAsync ( BootstrapMethod . Failure , null , ctx ) ;
92+ _logger . LogInformation ( "No semantic index existed yet, creating index {Index} for semantic search" , semanticIndex ) ;
9293 var semanticIndexPut = await _transport . PutAsync < StringResponse > ( semanticIndex , PostData . String ( "{}" ) , ctx ) ;
9394 if ( ! semanticIndexPut . ApiCallDetails . HasSuccessfulStatusCode )
9495 throw new Exception ( $ "Failed to create index { semanticIndex } : { semanticIndexPut } ") ;
95- _ = await _semanticChannel . Channel . ApplyAliasesAsync ( ctx ) ;
9696 if ( ! _endpoint . ForceReindex )
9797 {
9898 _indexStrategy = IngestStrategy . Multiplex ;
@@ -152,12 +152,13 @@ public async ValueTask StopAsync(Cancel ctx = default)
152152 throw new Exception ( $ "Failed to create index { semanticIndex } : { semanticIndexPut } ") ;
153153 _ = await _semanticChannel . Channel . ApplyAliasesAsync ( ctx ) ;
154154 }
155+ var destinationIndex = _semanticChannel . Channel . IndexName ;
155156
156- _logger . LogInformation ( "_reindex updates: '{SourceIndex}' => '{DestinationIndex}'" , lexicalWriteAlias , semanticWriteAlias ) ;
157+ _logger . LogInformation ( "_reindex updates: '{SourceIndex}' => '{DestinationIndex}'" , lexicalWriteAlias , destinationIndex ) ;
157158 var request = PostData . String ( @"
158159 {
159160 ""dest"": {
160- ""index"": """ + semanticWriteAlias + @"""
161+ ""index"": """ + destinationIndex + @"""
161162 },
162163 ""source"": {
163164 ""index"": """ + lexicalWriteAlias + @""",
@@ -171,13 +172,13 @@ public async ValueTask StopAsync(Cancel ctx = default)
171172 }
172173 }
173174 }" ) ;
174- await DoReindex ( request , lexicalWriteAlias , semanticWriteAlias , "updates" , ctx ) ;
175+ await DoReindex ( request , lexicalWriteAlias , destinationIndex , "updates" , ctx ) ;
175176
176- _logger . LogInformation ( "_reindex deletions: '{SourceIndex}' => '{DestinationIndex}'" , lexicalWriteAlias , semanticWriteAlias ) ;
177+ _logger . LogInformation ( "_reindex deletions: '{SourceIndex}' => '{DestinationIndex}'" , lexicalWriteAlias , destinationIndex ) ;
177178 request = PostData . String ( @"
178179 {
179180 ""dest"": {
180- ""index"": """ + semanticWriteAlias + @"""
181+ ""index"": """ + destinationIndex + @"""
181182 },
182183 ""script"": {
183184 ""source"": ""ctx.op = \""delete\""""
@@ -194,7 +195,7 @@ public async ValueTask StopAsync(Cancel ctx = default)
194195 }
195196 }
196197 }" ) ;
197- await DoReindex ( request , lexicalWriteAlias , semanticWriteAlias , "deletions" , ctx ) ;
198+ await DoReindex ( request , lexicalWriteAlias , destinationIndex , "deletions" , ctx ) ;
198199
199200 await DoDeleteByQuery ( lexicalWriteAlias , ctx ) ;
200201
@@ -336,6 +337,10 @@ public async ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext,
336337 ? body [ ..Math . Min ( body . Length , 400 ) ] + " " + string . Join ( " \n - " , headings )
337338 : string . Empty ;
338339
340+ // this is temporary until https://github.com/elastic/docs-builder/pull/2070 lands
341+ // this PR will add a service for us to resolve to a versioning scheme.
342+ var appliesTo = fileContext . SourceFile . YamlFrontMatter ? . AppliesTo ?? ApplicableTo . Default ;
343+
339344 var doc = new DocumentationDocument
340345 {
341346 Url = url ,
@@ -344,7 +349,7 @@ public async ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext,
344349 StrippedBody = body . StripMarkdown ( ) ,
345350 Description = fileContext . SourceFile . YamlFrontMatter ? . Description ,
346351 Abstract = @abstract ,
347- Applies = fileContext . SourceFile . YamlFrontMatter ? . AppliesTo ,
352+ Applies = appliesTo ,
348353 UrlSegmentCount = url . Split ( '/' , StringSplitOptions . RemoveEmptyEntries ) . Length ,
349354 Parents = navigation . GetParentsOfMarkdownFile ( file ) . Select ( i => new ParentDocument
350355 {
@@ -357,7 +362,7 @@ public async ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext,
357362 var semanticHash = _semanticChannel . Channel . ChannelHash ;
358363 var lexicalHash = _lexicalChannel . Channel . ChannelHash ;
359364 var hash = HashedBulkUpdate . CreateHash ( semanticHash , lexicalHash ,
360- doc . Url , doc . Body ?? string . Empty , string . Join ( "," , doc . Headings . OrderBy ( h => h ) )
365+ doc . Url , doc . Body ?? string . Empty , string . Join ( "," , doc . Headings . OrderBy ( h => h ) ) , doc . Url
361366 ) ;
362367 doc . Hash = hash ;
363368 doc . LastUpdated = _batchIndexDate ;
0 commit comments