Browse Source

Improve search list page and Pull function.

pull/4705/head
maliming 6 years ago
parent
commit
b38ef87468
  1. 45
      modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs
  2. 25
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

45
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<Document>();
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);
}
}

25
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<DocumentSearchOutput> SearchOutputs { get; set; } = new List<DocumentSearchOutput>();
@ -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("<highlight>", highlightTag1).Replace("</highlight>", highlightTag2))
.Replace(highlightTag1, "<highlight>").Replace(highlightTag2, "</highlight>");
}
}
return Page();
}
}
}
}

Loading…
Cancel
Save