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))
|
if (!ignoreEntities.Contains(searchContent.EntityName))
|
||||||
{
|
{
|
||||||
SaveModuleMetaData(searchContent, pageModule, tenantId, removed);
|
ValidateSearchContent(searchContent, pageModule, tenantId, removed);
|
||||||
searchContents.Add(searchContent);
|
searchContents.Add(searchContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,23 +148,8 @@ namespace Oqtane.Infrastructure
|
||||||
if (!searchable && changed && !ignoreEntities.Contains(EntityNames.Module))
|
if (!searchable && changed && !ignoreEntities.Contains(EntityNames.Module))
|
||||||
{
|
{
|
||||||
// module does not implement ISearchable
|
// module does not implement ISearchable
|
||||||
var searchContent = new SearchContent
|
var searchContent = new SearchContent();
|
||||||
{
|
ValidateSearchContent(searchContent, pageModule, tenantId, removed);
|
||||||
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
|
|
||||||
};
|
|
||||||
searchContents.Add(searchContent);
|
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.SiteId = pageModule.Module.SiteId;
|
||||||
searchContent.TenantId = tenantId;
|
searchContent.TenantId = tenantId;
|
||||||
|
searchContent.CreatedOn = DateTime.UtcNow;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(searchContent.EntityName))
|
if (string.IsNullOrEmpty(searchContent.EntityName))
|
||||||
{
|
{
|
||||||
|
@ -197,6 +184,31 @@ namespace Oqtane.Infrastructure
|
||||||
searchContent.EntityId = pageModule.ModuleId.ToString();
|
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))
|
if (string.IsNullOrEmpty(searchContent.Permissions))
|
||||||
{
|
{
|
||||||
searchContent.Permissions = $"{EntityNames.Module}:{pageModule.ModuleId},{EntityNames.Page}:{pageModule.PageId}";
|
searchContent.Permissions = $"{EntityNames.Module}:{pageModule.ModuleId},{EntityNames.Page}:{pageModule.PageId}";
|
||||||
|
@ -217,24 +229,10 @@ namespace Oqtane.Infrastructure
|
||||||
searchContent.AdditionalContent = string.Empty;
|
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))
|
if (removed || pageModule.IsDeleted || !Utilities.IsEffectiveOrExpired(pageModule.EffectiveDate, pageModule.ExpiryDate))
|
||||||
{
|
{
|
||||||
searchContent.IsDeleted = true;
|
searchContent.IsDeleted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveSearchLastIndexedOn(ISettingRepository settingRepository, int siteId, DateTime lastIndexedOn)
|
private void SaveSearchLastIndexedOn(ISettingRepository settingRepository, int siteId, DateTime lastIndexedOn)
|
||||||
|
|
|
@ -57,14 +57,11 @@ namespace Oqtane.Modules.Admin.Files.Manager
|
||||||
EntityName = EntityNames.File,
|
EntityName = EntityNames.File,
|
||||||
EntityId = file.FileId.ToString(),
|
EntityId = file.FileId.ToString(),
|
||||||
Title = path,
|
Title = path,
|
||||||
Description = string.Empty,
|
|
||||||
Body = body,
|
Body = body,
|
||||||
Url = $"{Constants.FileUrl}{folder.Path}{file.Name}",
|
Url = $"{Constants.FileUrl}{folder.Path}{file.Name}",
|
||||||
Permissions = $"{EntityNames.Folder}:{folder.FolderId}",
|
Permissions = $"{EntityNames.Folder}:{folder.FolderId}",
|
||||||
ContentModifiedBy = file.ModifiedBy,
|
ContentModifiedBy = file.ModifiedBy,
|
||||||
ContentModifiedOn = file.ModifiedOn,
|
ContentModifiedOn = file.ModifiedOn,
|
||||||
AdditionalContent = string.Empty,
|
|
||||||
CreatedOn = DateTime.UtcNow,
|
|
||||||
IsDeleted = (removed || file.IsDeleted.Value)
|
IsDeleted = (removed || file.IsDeleted.Value)
|
||||||
};
|
};
|
||||||
searchContents.Add(searchContent);
|
searchContents.Add(searchContent);
|
||||||
|
|
|
@ -61,8 +61,6 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||||
{
|
{
|
||||||
searchContents.Add(new SearchContent
|
searchContents.Add(new SearchContent
|
||||||
{
|
{
|
||||||
Title = pageModule.Module.Title,
|
|
||||||
Description = string.Empty,
|
|
||||||
Body = htmltext.Content,
|
Body = htmltext.Content,
|
||||||
ContentModifiedBy = htmltext.CreatedBy,
|
ContentModifiedBy = htmltext.CreatedBy,
|
||||||
ContentModifiedOn = htmltext.CreatedOn
|
ContentModifiedOn = htmltext.CreatedOn
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Oqtane.Models
|
namespace Oqtane.Models
|
||||||
{
|
{
|
||||||
public class SearchContent
|
public class SearchContent
|
||||||
|
@ -30,25 +31,25 @@ namespace Oqtane.Models
|
||||||
|
|
||||||
public string AdditionalContent { get; set; }
|
public string AdditionalContent { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
|
|
||||||
public DateTime CreatedOn { get; set; }
|
public DateTime CreatedOn { get; set; }
|
||||||
|
|
||||||
public List<SearchContentProperty> SearchContentProperties { get; set; }
|
public List<SearchContentProperty> SearchContentProperties { get; set; }
|
||||||
|
|
||||||
public List<SearchContentWord> SearchContentWords { get; set; }
|
public List<SearchContentWord> SearchContentWords { get; set; }
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
public string UniqueKey => $"{TenantId}:{SiteId}:{EntityName}:{EntityId}";
|
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int TenantId { get; set; }
|
public int TenantId { get; set; }
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public bool IsDeleted { get; set; }
|
public string UniqueKey => $"{TenantId}:{SiteId}:{EntityName}:{EntityId}";
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
public SearchContent() { }
|
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;
|
SiteId = siteId;
|
||||||
EntityName = entityName;
|
EntityName = entityName;
|
||||||
|
@ -60,8 +61,7 @@ namespace Oqtane.Models
|
||||||
Permissions = permissions;
|
Permissions = permissions;
|
||||||
ContentModifiedBy = contentModifiedBy;
|
ContentModifiedBy = contentModifiedBy;
|
||||||
ContentModifiedOn = contentModifiedOn;
|
ContentModifiedOn = contentModifiedOn;
|
||||||
AdditionalContent = "";
|
IsDeleted = isDeleted;
|
||||||
CreatedOn = DateTime.UtcNow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user