improve validation of seach content

This commit is contained in:
sbwalker
2024-07-20 19:17:47 -04:00
parent 740bcbd12c
commit 497f9ca0b1
4 changed files with 38 additions and 45 deletions

View File

@ -132,7 +132,7 @@ namespace Oqtane.Infrastructure
{
if (!ignoreEntities.Contains(searchContent.EntityName))
{
SaveModuleMetaData(searchContent, pageModule, tenantId, removed);
ValidateSearchContent(searchContent, pageModule, tenantId, removed);
searchContents.Add(searchContent);
}
}
@ -148,23 +148,8 @@ namespace Oqtane.Infrastructure
if (!searchable && changed && !ignoreEntities.Contains(EntityNames.Module))
{
// module does not implement ISearchable
var searchContent = new SearchContent
{
SiteId = page.SiteId,
EntityName = EntityNames.Module,
EntityId = pageModule.ModuleId.ToString(),
Title = pageModule.Title,
Description = string.Empty,
Body = string.Empty,
Url = $"{(!string.IsNullOrEmpty(page.Path) && !page.Path.StartsWith("/") ? "/" : "")}{page.Path}",
Permissions = $"{EntityNames.Module}:{pageModule.ModuleId},{EntityNames.Page}:{pageModule.PageId}",
ContentModifiedBy = pageModule.ModifiedBy,
ContentModifiedOn = pageModule.ModifiedOn,
AdditionalContent = string.Empty,
CreatedOn = DateTime.UtcNow,
IsDeleted = (removed || pageModule.IsDeleted || !Utilities.IsEffectiveOrExpired(pageModule.EffectiveDate, pageModule.ExpiryDate)),
TenantId = tenantId
};
var searchContent = new SearchContent();
ValidateSearchContent(searchContent, pageModule, tenantId, removed);
searchContents.Add(searchContent);
}
}
@ -182,10 +167,12 @@ namespace Oqtane.Infrastructure
}
private void SaveModuleMetaData(SearchContent searchContent, PageModule pageModule, int tenantId, bool removed)
private void ValidateSearchContent(SearchContent searchContent, PageModule pageModule, int tenantId, bool removed)
{
// set default values
searchContent.SiteId = pageModule.Module.SiteId;
searchContent.TenantId = tenantId;
searchContent.CreatedOn = DateTime.UtcNow;
if (string.IsNullOrEmpty(searchContent.EntityName))
{
@ -197,6 +184,31 @@ namespace Oqtane.Infrastructure
searchContent.EntityId = pageModule.ModuleId.ToString();
}
if (string.IsNullOrEmpty(searchContent.Title))
{
searchContent.Title = string.Empty;
if (!string.IsNullOrEmpty(pageModule.Title))
{
searchContent.Title = pageModule.Title;
}
else if (pageModule.Page != null)
{
searchContent.Title = !string.IsNullOrEmpty(pageModule.Page.Title) ? pageModule.Page.Title : pageModule.Page.Name;
}
}
if (searchContent.Description == null) { searchContent.Description = string.Empty;}
if (searchContent.Body == null) { searchContent.Body = string.Empty; }
if (string.IsNullOrEmpty(searchContent.Url))
{
searchContent.Url = string.Empty;
if (pageModule.Page != null)
{
searchContent.Url = $"{(!string.IsNullOrEmpty(pageModule.Page.Path) && !pageModule.Page.Path.StartsWith("/") ? "/" : "")}{pageModule.Page.Path}";
}
}
if (string.IsNullOrEmpty(searchContent.Permissions))
{
searchContent.Permissions = $"{EntityNames.Module}:{pageModule.ModuleId},{EntityNames.Page}:{pageModule.PageId}";
@ -217,24 +229,10 @@ namespace Oqtane.Infrastructure
searchContent.AdditionalContent = string.Empty;
}
if (pageModule.Page != null)
{
if (string.IsNullOrEmpty(searchContent.Url))
{
searchContent.Url = $"{(!string.IsNullOrEmpty(pageModule.Page.Path) && !pageModule.Page.Path.StartsWith("/") ? "/" : "")}{pageModule.Page.Path}";
}
if (string.IsNullOrEmpty(searchContent.Title))
{
searchContent.Title = !string.IsNullOrEmpty(pageModule.Page.Title) ? pageModule.Page.Title : pageModule.Page.Name;
}
}
if (removed || pageModule.IsDeleted || !Utilities.IsEffectiveOrExpired(pageModule.EffectiveDate, pageModule.ExpiryDate))
{
searchContent.IsDeleted = true;
}
}
private void SaveSearchLastIndexedOn(ISettingRepository settingRepository, int siteId, DateTime lastIndexedOn)

View File

@ -57,14 +57,11 @@ namespace Oqtane.Modules.Admin.Files.Manager
EntityName = EntityNames.File,
EntityId = file.FileId.ToString(),
Title = path,
Description = string.Empty,
Body = body,
Url = $"{Constants.FileUrl}{folder.Path}{file.Name}",
Permissions = $"{EntityNames.Folder}:{folder.FolderId}",
ContentModifiedBy = file.ModifiedBy,
ContentModifiedOn = file.ModifiedOn,
AdditionalContent = string.Empty,
CreatedOn = DateTime.UtcNow,
IsDeleted = (removed || file.IsDeleted.Value)
};
searchContents.Add(searchContent);

View File

@ -61,8 +61,6 @@ namespace Oqtane.Modules.HtmlText.Manager
{
searchContents.Add(new SearchContent
{
Title = pageModule.Module.Title,
Description = string.Empty,
Body = htmltext.Content,
ContentModifiedBy = htmltext.CreatedBy,
ContentModifiedOn = htmltext.CreatedOn