You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.3 KiB
C#

using Microsoft.EntityFrameworkCore;
namespace Admin.NET.Plugin.HwPortal;
public sealed class HwSearchRebuildService : IHwSearchRebuildService, ITransient
{
private readonly HwPortalSearchDbContext _db;
private readonly IHwSearchSchemaService _schemaService;
private readonly IHwSearchIndexService _indexService;
private readonly HwWebMenuService _menuService;
private readonly HwWebService _webService;
private readonly HwWeb1Service _web1Service;
private readonly HwWebDocumentService _documentService;
private readonly HwPortalConfigTypeService _configTypeService;
public HwSearchRebuildService(
HwPortalSearchDbContext db,
IHwSearchSchemaService schemaService,
IHwSearchIndexService indexService,
HwWebMenuService menuService,
HwWebService webService,
HwWeb1Service web1Service,
HwWebDocumentService documentService,
HwPortalConfigTypeService configTypeService)
{
_db = db;
_schemaService = schemaService;
_indexService = indexService;
_menuService = menuService;
_webService = webService;
_web1Service = web1Service;
_documentService = documentService;
_configTypeService = configTypeService;
}
public async Task RebuildAllAsync()
{
await _schemaService.EnsureCreatedAsync();
await _db.Database.ExecuteSqlRawAsync("DELETE FROM `hw_portal_search_doc`;");
foreach (HwWebMenu item in await _menuService.SelectHwWebMenuList(new HwWebMenu()))
{
await _indexService.UpsertMenuAsync(item);
}
foreach (HwWeb item in await _webService.SelectHwWebList(new HwWeb()))
{
await _indexService.UpsertWebAsync(item);
}
foreach (HwWeb1 item in await _web1Service.SelectHwWebList(new HwWeb1()))
{
await _indexService.UpsertWeb1Async(item);
}
foreach (HwWebDocument item in await _documentService.SelectHwWebDocumentList(new HwWebDocument()))
{
await _indexService.UpsertDocumentAsync(item);
}
foreach (HwPortalConfigType item in await _configTypeService.SelectHwPortalConfigTypeList(new HwPortalConfigType()))
{
await _indexService.UpsertConfigTypeAsync(item);
}
}
}