Browse Source

Add paging to docs module search result

pull/16939/head
Salih 3 years ago
parent
commit
bbec7d4aa2
  1. 3
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs
  2. 11
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  3. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs
  4. 15
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/EsDocumentResult.cs
  5. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/IDocumentFullSearch.cs
  6. 3
      modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs
  7. 78
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml
  8. 26
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

3
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
namespace Volo.Docs.Documents namespace Volo.Docs.Documents
@ -16,7 +17,7 @@ namespace Volo.Docs.Documents
Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input); Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input);
Task<List<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input); Task<PagedResultDto<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input);
Task<bool> FullSearchEnabledAsync(); Task<bool> FullSearchEnabledAsync();

11
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs

@ -9,6 +9,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Docs.Caching; using Volo.Docs.Caching;
using Volo.Docs.Documents.FullSearch.Elastic; using Volo.Docs.Documents.FullSearch.Elastic;
@ -176,16 +177,16 @@ namespace Volo.Docs.Documents
); );
} }
public async Task<List<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input) public async Task<PagedResultDto<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input)
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version; input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var esDocs = var esDocResult =
await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version); await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version, input.SkipCount, input.MaxResultCount);
return esDocs.Select(esDoc => new DocumentSearchOutput //TODO: auto map return new PagedResultDto<DocumentSearchOutput>(esDocResult.TotalCount,esDocResult.EsDocuments.Select(esDoc => new DocumentSearchOutput //TODO: auto map
{ {
Name = esDoc.Name, Name = esDoc.Name,
FileName = esDoc.FileName, FileName = esDoc.FileName,
@ -194,7 +195,7 @@ namespace Volo.Docs.Documents
Highlight = esDoc.Highlight Highlight = esDoc.Highlight
}).Where(x => }).Where(x =>
x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName) x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName)
.ToList(); .ToList());
} }
public async Task<bool> FullSearchEnabledAsync() public async Task<bool> FullSearchEnabledAsync()

4
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs

@ -138,7 +138,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
.DeleteByQueryAsync(request, cancellationToken)); .DeleteByQueryAsync(request, cancellationToken));
} }
public virtual async Task<List<EsDocument>> SearchAsync(string context, Guid projectId, string languageCode, public virtual async Task<EsDocumentResult> SearchAsync(string context, Guid projectId, string languageCode,
string version, int? skipCount = null, int? maxResultCount = null, string version, int? skipCount = null, int? maxResultCount = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -212,7 +212,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
docs.Add(doc); docs.Add(doc);
} }
return docs; return new EsDocumentResult { EsDocuments = docs, TotalCount = response.Total };
} }
protected virtual void HandleError(IElasticsearchResponse response) protected virtual void HandleError(IElasticsearchResponse response)

15
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/EsDocumentResult.cs

@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace Volo.Docs.Documents.FullSearch.Elastic;
public class EsDocumentResult
{
public EsDocumentResult()
{
EsDocuments = new List<EsDocument>();
}
public long TotalCount { get; set; }
public List<EsDocument> EsDocuments { get; set; }
}

2
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/IDocumentFullSearch.cs

@ -19,7 +19,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
Task DeleteAllByProjectIdAsync(Guid projectId, CancellationToken cancellationToken = default); Task DeleteAllByProjectIdAsync(Guid projectId, CancellationToken cancellationToken = default);
Task<List<EsDocument>> SearchAsync(string context, Guid projectId, string languageCode, Task<EsDocumentResult> SearchAsync(string context, Guid projectId, string languageCode,
string version, int? skipCount = null, int? maxResultCount = null, string version, int? skipCount = null, int? maxResultCount = null,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);

3
modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
namespace Volo.Docs.Documents namespace Volo.Docs.Documents
@ -49,7 +50,7 @@ namespace Volo.Docs.Documents
[HttpPost] [HttpPost]
[Route("search")] [Route("search")]
public Task<List<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input) public Task<PagedResultDto<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input)
{ {
return DocumentAppService.SearchAsync(input); return DocumentAppService.SearchAsync(input);
} }

78
modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml

@ -41,45 +41,53 @@
</div> </div>
</form> </form>
<div class="card mt-4 rounded"> @if (!Model.KeyWord.IsNullOrWhiteSpace())
<div class="card-header"> {
<h5 class="text-center ">@L["SearchResults"]</h5> <div class="card mt-4 rounded">
</div> <div class="card-header">
<div class="p-5 card-body"> <h5 class="text-center ">@L["SearchResults"]</h5>
@foreach (var docs in Model.SearchOutputs) </div>
{ <div class="px-5 pt-5 card-body">
<div class="row"> @foreach (var docs in Model.SearchOutputs)
<div class="col"> {
<div class="pb-4 small"> <div class="row">
@functions <div class="col">
{ <div class="pb-4 small">
string RemoveFileExtensionFromPath(string path) @functions
{ {
if (path == null) string RemoveFileExtensionFromPath(string path)
{ {
return null; if (path == null)
{
return null;
}
return path.EndsWith("." + @Model.Project.Format)
? path.Left(path.Length - Model.Project.Format.Length - 1)
: path;
} }
return path.EndsWith("." + @Model.Project.Format)
? path.Left(path.Length - Model.Project.Format.Length - 1)
: path;
} }
} <h5 class="mb-3">
<h5 class="mb-3"> <a href="/@Model.LanguageCode/@Model.ProjectName/@Model.Version/@RemoveFileExtensionFromPath(docs.Name)">
<a href="/@Model.LanguageCode/@Model.ProjectName/@Model.Version/@RemoveFileExtensionFromPath(docs.Name)"> @RemoveFileExtensionFromPath(docs.Name)
@RemoveFileExtensionFromPath(docs.Name) </a>
</a> </h5>
</h5> <div class="mb-4">
<div class="mb-4"> @foreach (var highlight in docs.Highlight)
@foreach (var highlight in docs.Highlight) {
{ <p class="mb-2">@Html.Raw(highlight)</p>
<p class="mb-2">@Html.Raw(highlight)</p> }
} </div>
</div> </div>
</div> </div>
</div> </div>
</div> }
} @if (Model.PagerModel != null)
{
<abp-paginator model="Model.PagerModel" show-info="true" />
}
</div>
</div> </div>
</div> }
</div> </div>

26
modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using System.Web; using System.Web;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination;
using Volo.Docs.Documents; using Volo.Docs.Documents;
using Volo.Docs.GitHub.Documents.Version; using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.HtmlConverting; using Volo.Docs.HtmlConverting;
@ -24,6 +25,10 @@ namespace Volo.Docs.Pages.Documents
[BindProperty(SupportsGet = true)] public string LanguageCode { get; set; } [BindProperty(SupportsGet = true)] public string LanguageCode { get; set; }
[BindProperty(SupportsGet = true)] public string KeyWord { get; set; } [BindProperty(SupportsGet = true)] public string KeyWord { get; set; }
[BindProperty(SupportsGet = true)] public int CurrentPage { get; set; } = 1;
public PagerModel PagerModel { get; set; }
public ProjectDto Project { get; set; } public ProjectDto Project { get; set; }
@ -49,6 +54,11 @@ namespace Volo.Docs.Pages.Documents
return RedirectToPage("Index"); return RedirectToPage("Index");
} }
if (keyword.IsNullOrWhiteSpace())
{
return Page();
}
KeyWord = keyword; KeyWord = keyword;
Project = await _projectAppService.GetAsync(ProjectName); Project = await _projectAppService.GetAsync(ProjectName);
@ -72,13 +82,25 @@ namespace Volo.Docs.Pages.Documents
} }
} }
SearchOutputs = await _documentAppService.SearchAsync(new DocumentSearchInput var pagedSearchOutputs = await _documentAppService.SearchAsync(new DocumentSearchInput
{ {
ProjectId = Project.Id, ProjectId = Project.Id,
Context = KeyWord, Context = KeyWord,
LanguageCode = LanguageCode, LanguageCode = LanguageCode,
Version = Version Version = Version,
MaxResultCount = 10,
SkipCount = (CurrentPage - 1) * 10
}); });
SearchOutputs = pagedSearchOutputs.Items.ToList();
PagerModel = new PagerModel(pagedSearchOutputs.TotalCount, 10, CurrentPage, 10, Url.Page("Search", new
{
ProjectName,
Version,
LanguageCode,
KeyWord
}));
var highlightTag1 = Guid.NewGuid().ToString(); var highlightTag1 = Guid.NewGuid().ToString();
var highlightTag2 = Guid.NewGuid().ToString(); var highlightTag2 = Guid.NewGuid().ToString();

Loading…
Cancel
Save