improve validation of seach content
This commit is contained in:
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user