Browse Source

Merge pull request #4705 from abpframework/maliming/es-patch

Improve the docs module.
pull/4746/head
liangshiwei 6 years ago
committed by GitHub
parent
commit
3a7e086ce4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs
  2. 4
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  3. 9
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs
  4. 25
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

17
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;
@ -100,14 +102,21 @@ namespace Volo.Docs.Admin.Documents
foreach (var leaf in leafs)
{
if (leaf.Path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) ||
(leaf.Path.StartsWith("{{") && leaf.Path.EndsWith("}}")))
{
continue;
}
var sourceDocument =
await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version);
documents.Add(sourceDocument);
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)

4
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<bool> FullSearchEnabledAsync()
@ -338,4 +338,4 @@ namespace Volo.Docs.Documents
return TimeSpan.Parse(value);
}
}
}
}

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

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