From 0253eeaa72c9c61ef5f42324e6d1ca2c143d5328 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Thu, 9 Jul 2020 22:13:58 +0800 Subject: [PATCH 1/4] Convert special characters in LanguageCode. --- .../FullSearch/Elastic/ElasticDocumentFullSearch.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs index cbe5905d3a..05a3f1c4c8 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs @@ -72,7 +72,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic Name = document.Name, FileName = document.FileName, Content = document.Content, - LanguageCode = document.LanguageCode, + LanguageCode = ConvertLanguageCode(document.LanguageCode), Version = document.Version }; @@ -178,7 +178,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic new TermQuery { Field = "languageCode", - Value = languageCode + Value = ConvertLanguageCode(languageCode) } } } @@ -232,5 +232,10 @@ namespace Volo.Docs.Documents.FullSearch.Elastic throw new BusinessException(DocsDomainErrorCodes.ElasticSearchNotEnabled); } } + + protected string ConvertLanguageCode(string languageCode) + { + return languageCode.Replace("-", "").ToLower(); + } } } From 54394b30f286fb92055e99d04197f479ed5d1054 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Thu, 9 Jul 2020 22:38:19 +0800 Subject: [PATCH 2/4] Filter Navigation and Parameters in the search results. --- .../Volo/Docs/Documents/DocumentAppService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs index 02bb535f50..6cacf9d3e3 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs @@ -176,7 +176,7 @@ namespace Volo.Docs.Documents Version = esDoc.Version, LanguageCode = esDoc.LanguageCode, Highlight = esDoc.Highlight - }).ToList(); + }).Where(x => x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName).ToList(); } public async Task FullSearchEnabledAsync() @@ -338,4 +338,4 @@ namespace Volo.Docs.Documents return TimeSpan.Parse(value); } } -} \ No newline at end of file +} From b38ef874681d5d1bdc672e6d27bc4d86dc60308b Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Fri, 10 Jul 2020 09:02:58 +0800 Subject: [PATCH 3/4] Improve search list page and Pull function. --- .../Documents/DocumentAdminAppService.cs | 45 +++++++++++-------- .../Pages/Documents/Search.cshtml.cs | 25 +++++++++-- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs index cb6443d268..ff6c7bc654 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Logging; using Volo.Abp; +using Volo.Abp.Uow; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Caching; @@ -96,28 +98,35 @@ namespace Volo.Docs.Admin.Documents var source = _documentStoreFactory.Create(project.DocumentStoreType); - var documents = new List(); foreach (var leaf in leafs) { - if (leaf.Path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || - leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) + using (var uow = UnitOfWorkManager.Begin(requiresNew: true)) { - continue; + if (leaf.Path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || + leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || + (leaf.Path.StartsWith("{{") && leaf.Path.EndsWith("}}"))) + { + continue; + } + + try + { + var sourceDocument = await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version); + + await _documentRepository.DeleteAsync(sourceDocument.ProjectId, sourceDocument.Name, + sourceDocument.LanguageCode, + sourceDocument.Version); + + await _documentRepository.InsertAsync(sourceDocument, true); + await UpdateDocumentUpdateInfoCache(sourceDocument); + + await uow.CompleteAsync(); + } + catch (Exception e) + { + Logger.LogException(e); + } } - - var sourceDocument = - await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version); - documents.Add(sourceDocument); - } - - foreach (var document in documents) - { - await _documentRepository.DeleteAsync(document.ProjectId, document.Name, - document.LanguageCode, - document.Version); - - await _documentRepository.InsertAsync(document, true); - await UpdateDocumentUpdateInfoCache(document); } } diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs index 702141bc1e..1e4e797e73 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Encodings.Web; using System.Threading.Tasks; +using System.Web; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Volo.Docs.Documents; @@ -29,12 +31,15 @@ namespace Volo.Docs.Pages.Documents private readonly IProjectAppService _projectAppService; private readonly IDocumentAppService _documentAppService; + private readonly HtmlEncoder _encoder; - public SearchModel(IProjectAppService projectAppService, - IDocumentAppService documentAppService) + public SearchModel(IProjectAppService projectAppService, + IDocumentAppService documentAppService, + HtmlEncoder encoder) { _projectAppService = projectAppService; _documentAppService = documentAppService; + _encoder = encoder; } public List SearchOutputs { get; set; } = new List(); @@ -45,7 +50,7 @@ namespace Volo.Docs.Pages.Documents { return RedirectToPage("Index"); } - + KeyWord = keyword; Project = await _projectAppService.GetAsync(ProjectName); @@ -67,7 +72,19 @@ namespace Volo.Docs.Pages.Documents Version = Version }); + var highlightTag1 = Guid.NewGuid().ToString(); + var highlightTag2 = Guid.NewGuid().ToString(); + foreach (var searchOutput in SearchOutputs) + { + for (var i = 0; i < searchOutput.Highlight.Count; i++) + { + searchOutput.Highlight[i] = _encoder + .Encode(searchOutput.Highlight[i].Replace("", highlightTag1).Replace("", highlightTag2)) + .Replace(highlightTag1, "").Replace(highlightTag2, ""); + } + } + return Page(); } } -} \ No newline at end of file +} From 865be7ae78d55052228b4fb0e39955ac09235c84 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Fri, 10 Jul 2020 09:12:56 +0800 Subject: [PATCH 4/4] Update DocumentAdminAppService. --- .../Documents/DocumentAdminAppService.cs | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs index ff6c7bc654..c6758127cf 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs @@ -98,35 +98,35 @@ namespace Volo.Docs.Admin.Documents var source = _documentStoreFactory.Create(project.DocumentStoreType); + var documents = new List(); foreach (var leaf in leafs) { - using (var uow = UnitOfWorkManager.Begin(requiresNew: true)) + if (leaf.Path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || + leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || + (leaf.Path.StartsWith("{{") && leaf.Path.EndsWith("}}"))) { - if (leaf.Path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || - leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || - (leaf.Path.StartsWith("{{") && leaf.Path.EndsWith("}}"))) - { - continue; - } - - try - { - var sourceDocument = await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version); - - await _documentRepository.DeleteAsync(sourceDocument.ProjectId, sourceDocument.Name, - sourceDocument.LanguageCode, - sourceDocument.Version); - - await _documentRepository.InsertAsync(sourceDocument, true); - await UpdateDocumentUpdateInfoCache(sourceDocument); - - await uow.CompleteAsync(); - } - catch (Exception e) - { - Logger.LogException(e); - } + continue; } + + try + { + var sourceDocument = await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version); + documents.Add(sourceDocument); + } + catch (Exception e) + { + Logger.LogException(e); + } + } + + foreach (var document in documents) + { + await _documentRepository.DeleteAsync(document.ProjectId, document.Name, + document.LanguageCode, + document.Version); + + await _documentRepository.InsertAsync(document, true); + await UpdateDocumentUpdateInfoCache(document); } }