improve validation of seach content
This commit is contained in:
parent
740bcbd12c
commit
497f9ca0b1
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
public class SearchContent
|
||||
|
@ -30,25 +31,25 @@ namespace Oqtane.Models
|
|||
|
||||
public string AdditionalContent { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public DateTime CreatedOn { get; set; }
|
||||
|
||||
public List<SearchContentProperty> SearchContentProperties { get; set; }
|
||||
|
||||
public List<SearchContentWord> SearchContentWords { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public string UniqueKey => $"{TenantId}:{SiteId}:{EntityName}:{EntityId}";
|
||||
|
||||
[NotMapped]
|
||||
public int TenantId { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public bool IsDeleted { get; set; }
|
||||
public string UniqueKey => $"{TenantId}:{SiteId}:{EntityName}:{EntityId}";
|
||||
|
||||
// constructors
|
||||
public SearchContent() { }
|
||||
|
||||
public SearchContent(int siteId, string entityName, string entityId, string title, string description, string body, string url, string permissions, string contentModifiedBy, DateTime contentModifiedOn)
|
||||
public SearchContent(int siteId, string entityName, string entityId, string title, string description, string body, string url, string permissions, string contentModifiedBy, DateTime contentModifiedOn, bool isDeleted)
|
||||
{
|
||||
SiteId = siteId;
|
||||
EntityName = entityName;
|
||||
|
@ -60,8 +61,7 @@ namespace Oqtane.Models
|
|||
Permissions = permissions;
|
||||
ContentModifiedBy = contentModifiedBy;
|
||||
ContentModifiedOn = contentModifiedOn;
|
||||
AdditionalContent = "";
|
||||
CreatedOn = DateTime.UtcNow;
|
||||
IsDeleted = isDeleted;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
Loading…
Reference in New Issue
Block a user