Add paging to docs module search result

pull/16939/head
Salih 2 years ago
parent c520b4a09f
commit bbec7d4aa2

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

@ -9,6 +9,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching;
using Volo.Docs.Caching;
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);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var esDocs =
await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version);
var esDocResult =
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,
FileName = esDoc.FileName,
@ -194,7 +195,7 @@ namespace Volo.Docs.Documents
Highlight = esDoc.Highlight
}).Where(x =>
x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName)
.ToList();
.ToList());
}
public async Task<bool> FullSearchEnabledAsync()

@ -138,7 +138,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
.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,
CancellationToken cancellationToken = default)
{
@ -212,7 +212,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
docs.Add(doc);
}
return docs;
return new EsDocumentResult { EsDocuments = docs, TotalCount = response.Total };
}
protected virtual void HandleError(IElasticsearchResponse response)

@ -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; }
}

@ -19,7 +19,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
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,
CancellationToken cancellationToken = default);

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

@ -41,11 +41,13 @@
</div>
</form>
@if (!Model.KeyWord.IsNullOrWhiteSpace())
{
<div class="card mt-4 rounded">
<div class="card-header">
<h5 class="text-center ">@L["SearchResults"]</h5>
</div>
<div class="p-5 card-body">
<div class="px-5 pt-5 card-body">
@foreach (var docs in Model.SearchOutputs)
{
<div class="row">
@ -80,6 +82,12 @@
</div>
</div>
}
@if (Model.PagerModel != null)
{
<abp-paginator model="Model.PagerModel" show-info="true" />
}
</div>
</div>
}
</div>

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination;
using Volo.Docs.Documents;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.HtmlConverting;
@ -25,6 +26,10 @@ namespace Volo.Docs.Pages.Documents
[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; }
private readonly IProjectAppService _projectAppService;
@ -49,6 +54,11 @@ namespace Volo.Docs.Pages.Documents
return RedirectToPage("Index");
}
if (keyword.IsNullOrWhiteSpace())
{
return Page();
}
KeyWord = keyword;
Project = await _projectAppService.GetAsync(ProjectName);
@ -72,14 +82,26 @@ namespace Volo.Docs.Pages.Documents
}
}
SearchOutputs = await _documentAppService.SearchAsync(new DocumentSearchInput
var pagedSearchOutputs = await _documentAppService.SearchAsync(new DocumentSearchInput
{
ProjectId = Project.Id,
Context = KeyWord,
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 highlightTag2 = Guid.NewGuid().ToString();
foreach (var searchOutput in SearchOutputs)

Loading…
Cancel
Save