#4303: add search function.

This commit is contained in:
Ben
2024-06-03 21:19:42 +08:00
parent d75e3acdf3
commit 9d85ca07f4
50 changed files with 2478 additions and 4 deletions

View File

@ -8,20 +8,29 @@ using Oqtane.Shared;
using Oqtane.Migrations.Framework;
using Oqtane.Documentation;
using System.Linq;
using Oqtane.Interfaces;
using System.Collections.Generic;
using System;
// ReSharper disable ConvertToUsingDeclaration
namespace Oqtane.Modules.HtmlText.Manager
{
[PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")]
public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable
public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable, IModuleSearch
{
private readonly IServiceProvider _serviceProvider;
private readonly IHtmlTextRepository _htmlText;
private readonly IDBContextDependencies _DBContextDependencies;
private readonly ISqlRepository _sqlRepository;
public HtmlTextManager(IHtmlTextRepository htmlText, IDBContextDependencies DBContextDependencies, ISqlRepository sqlRepository)
public HtmlTextManager(
IServiceProvider serviceProvider,
IHtmlTextRepository htmlText,
IDBContextDependencies DBContextDependencies,
ISqlRepository sqlRepository)
{
_serviceProvider = serviceProvider;
_htmlText = htmlText;
_DBContextDependencies = DBContextDependencies;
_sqlRepository = sqlRepository;
@ -39,6 +48,27 @@ namespace Oqtane.Modules.HtmlText.Manager
return content;
}
public IList<SearchDocument> GetSearchDocuments(Module module, DateTime startDate)
{
var searchDocuments = new List<SearchDocument>();
var htmltexts = _htmlText.GetHtmlTexts(module.ModuleId);
if (htmltexts != null && htmltexts.Any(i => i.CreatedOn >= startDate))
{
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
searchDocuments.Add(new SearchDocument
{
Title = module.Title,
Description = string.Empty,
Body = SearchUtils.Clean(htmltext.Content, true),
ModifiedTime = htmltext.ModifiedOn
});
}
return searchDocuments;
}
public void ImportModule(Module module, string content, string version)
{
content = WebUtility.HtmlDecode(content);