Browse Source
Merge pull request #11686 from abpframework/liangshiwei/docs
Enhance Docs Module
pull/11693/head
maliming
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
28 additions and
15 deletions
-
modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs
-
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs
-
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/IDocumentFullSearch.cs
-
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
@ -134,22 +135,14 @@ namespace Volo.Docs.Admin.Projects |
|
|
|
throw new Exception("Cannot find the project with the Id " + projectId); |
|
|
|
} |
|
|
|
|
|
|
|
var docs = await _documentRepository.GetListByProjectId(project.Id); |
|
|
|
var docs = (await _documentRepository.GetListByProjectId(project.Id)) |
|
|
|
.Where(doc => doc.FileName != project.NavigationDocumentName && doc.FileName != project.ParametersDocumentName) |
|
|
|
.ToList(); |
|
|
|
await _elasticSearchService.DeleteAllByProjectIdAsync(project.Id); |
|
|
|
|
|
|
|
foreach (var doc in docs) |
|
|
|
if(docs.Any()) |
|
|
|
{ |
|
|
|
if (doc.FileName == project.NavigationDocumentName) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (doc.FileName == project.ParametersDocumentName) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
await _elasticSearchService.AddOrUpdateAsync(doc); |
|
|
|
await _elasticSearchService.AddOrUpdateManyAsync(docs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Elasticsearch.Net; |
|
|
|
@ -69,7 +70,24 @@ namespace Volo.Docs.Documents.FullSearch.Elastic |
|
|
|
Version = NormalizeField(document.Version) |
|
|
|
}; |
|
|
|
|
|
|
|
await client.IndexAsync(esDocument, x => x.Index(_options.IndexName), cancellationToken); |
|
|
|
HandleError(await client.IndexAsync(esDocument, x => x.Index(_options.IndexName), cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task AddOrUpdateManyAsync(IEnumerable<Document> documents, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var client = _clientProvider.GetClient(); |
|
|
|
|
|
|
|
var esDocuments = documents.Select(x => new EsDocument { |
|
|
|
Id = NormalizeField(x.Id), |
|
|
|
ProjectId = NormalizeField(x.ProjectId), |
|
|
|
Name = x.Name, |
|
|
|
FileName = x.FileName, |
|
|
|
Content = x.Content, |
|
|
|
LanguageCode = NormalizeField(x.LanguageCode), |
|
|
|
Version = NormalizeField(x.Version) |
|
|
|
}); |
|
|
|
|
|
|
|
HandleError(await client.IndexManyAsync(esDocuments, _options.IndexName, cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default) |
|
|
|
|
|
|
|
@ -11,6 +11,8 @@ namespace Volo.Docs.Documents.FullSearch.Elastic |
|
|
|
|
|
|
|
Task AddOrUpdateAsync(Document document, CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task AddOrUpdateManyAsync(IEnumerable<Document> documents, CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task DeleteAsync(Guid id, CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task DeleteAllAsync(CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
@ -383,7 +383,7 @@ namespace Volo.Docs.GitHub.Documents |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
//TODO: Only handle when document is really not available
|
|
|
|
Logger.LogWarning(ex.Message, ex); |
|
|
|
Logger.LogWarning($"{ex.Message}: {rawUrl}", ex); |
|
|
|
throw new DocumentNotFoundException(rawUrl); |
|
|
|
} |
|
|
|
} |
|
|
|
|