use PageModule in ISearchable

This commit is contained in:
sbwalker 2024-07-02 14:50:26 -04:00
parent 45b1d405a6
commit 8969b1273f
3 changed files with 11 additions and 12 deletions

View File

@ -49,17 +49,16 @@ namespace Oqtane.Managers.Search
continue; continue;
} }
var module = pageModule.Module; if (pageModule.Module.ModuleDefinition != null && pageModule.Module.ModuleDefinition.ServerManagerType != "")
if (module.ModuleDefinition != null && module.ModuleDefinition.ServerManagerType != "")
{ {
_logger.LogDebug($"Search: Begin index module {module.ModuleId}."); _logger.LogDebug($"Search: Begin index module {pageModule.ModuleId}.");
var type = Type.GetType(module.ModuleDefinition.ServerManagerType); var type = Type.GetType(pageModule.Module.ModuleDefinition.ServerManagerType);
if (type?.GetInterface(nameof(ISearchable)) != null) if (type?.GetInterface(nameof(ISearchable)) != null)
{ {
try try
{ {
var moduleSearch = (ISearchable)ActivatorUtilities.CreateInstance(_serviceProvider, type); var moduleSearch = (ISearchable)ActivatorUtilities.CreateInstance(_serviceProvider, type);
var contentList = moduleSearch.GetSearchContents(module, startTime.GetValueOrDefault(DateTime.MinValue)); var contentList = moduleSearch.GetSearchContents(pageModule, startTime.GetValueOrDefault(DateTime.MinValue));
if(contentList != null) if(contentList != null)
{ {
foreach(var searchContent in contentList) foreach(var searchContent in contentList)
@ -73,11 +72,11 @@ namespace Oqtane.Managers.Search
} }
catch(Exception ex) catch(Exception ex)
{ {
_logger.LogError(ex, $"Search: Index module {module.ModuleId} failed."); _logger.LogError(ex, $"Search: Index module {pageModule.ModuleId} failed.");
handleError($"Search: Index module {module.ModuleId} failed: {ex.Message}"); handleError($"Search: Index module {pageModule.ModuleId} failed: {ex.Message}");
} }
} }
_logger.LogDebug($"Search: End index module {module.ModuleId}."); _logger.LogDebug($"Search: End index module {pageModule.ModuleId}.");
} }
} }

View File

@ -48,18 +48,18 @@ namespace Oqtane.Modules.HtmlText.Manager
return content; return content;
} }
public List<SearchContent> GetSearchContents(Module module, DateTime startDate) public List<SearchContent> GetSearchContents(PageModule pageModule, DateTime startDate)
{ {
var searchContentList = new List<SearchContent>(); var searchContentList = new List<SearchContent>();
var htmltexts = _htmlText.GetHtmlTexts(module.ModuleId); var htmltexts = _htmlText.GetHtmlTexts(pageModule.ModuleId);
if (htmltexts != null && htmltexts.Any(i => i.CreatedOn >= startDate)) if (htmltexts != null && htmltexts.Any(i => i.CreatedOn >= startDate))
{ {
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First(); var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
searchContentList.Add(new SearchContent searchContentList.Add(new SearchContent
{ {
Title = module.Title, Title = pageModule.Module.Title,
Description = string.Empty, Description = string.Empty,
Body = htmltext.Content, Body = htmltext.Content,
ContentModifiedBy = htmltext.ModifiedBy, ContentModifiedBy = htmltext.ModifiedBy,

View File

@ -6,6 +6,6 @@ namespace Oqtane.Interfaces
{ {
public interface ISearchable public interface ISearchable
{ {
public List<SearchContent> GetSearchContents(Module module, DateTime startTime); public List<SearchContent> GetSearchContents(PageModule pageModule, DateTime startTime);
} }
} }