Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the docs module. #4705

Merged
merged 4 commits into from Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,7 +3,9 @@
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;
Expand Down Expand Up @@ -100,14 +102,21 @@ public async Task PullAllAsync(PullAllDocumentInput input)
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)
Expand Down
Expand Up @@ -176,7 +176,7 @@ public async Task<List<DocumentSearchOutput>> SearchAsync(DocumentSearchInput in
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()
Expand Down Expand Up @@ -338,4 +338,4 @@ private TimeSpan GetDocumentResourceSlidingExpirationTimeout()
return TimeSpan.Parse(value);
}
}
}
}
Expand Up @@ -72,7 +72,7 @@ public async Task AddOrUpdateAsync(Document document, CancellationToken cancella
Name = document.Name,
FileName = document.FileName,
Content = document.Content,
LanguageCode = document.LanguageCode,
LanguageCode = ConvertLanguageCode(document.LanguageCode),
Version = document.Version
};

Expand Down Expand Up @@ -178,7 +178,7 @@ public async Task DeleteAllByProjectIdAsync(Guid projectId, CancellationToken ca
new TermQuery
{
Field = "languageCode",
Value = languageCode
Value = ConvertLanguageCode(languageCode)
}
}
}
Expand Down Expand Up @@ -232,5 +232,10 @@ protected void ValidateElasticSearchEnabled()
throw new BusinessException(DocsDomainErrorCodes.ElasticSearchNotEnabled);
}
}

protected string ConvertLanguageCode(string languageCode)
{
return languageCode.Replace("-", "").ToLower();
}
}
}
25 changes: 21 additions & 4 deletions 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;
Expand Down Expand Up @@ -29,12 +31,15 @@ public class SearchModel : PageModel

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>();
Expand All @@ -45,7 +50,7 @@ public virtual async Task<IActionResult> OnGetAsync(string keyword)
{
return RedirectToPage("Index");
}

KeyWord = keyword;

Project = await _projectAppService.GetAsync(ProjectName);
Expand All @@ -67,7 +72,19 @@ public virtual async Task<IActionResult> OnGetAsync(string keyword)
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();
}
}
}
}