testing search indexing of files

This commit is contained in:
sbwalker
2024-07-13 09:28:02 -04:00
parent 938eee80a9
commit c3f041dc87
6 changed files with 109 additions and 12 deletions

View File

@ -0,0 +1,82 @@
using Oqtane.Models;
using Oqtane.Repository;
using Oqtane.Documentation;
using Oqtane.Interfaces;
using System.Collections.Generic;
using System;
using System.Threading.Tasks;
using Oqtane.Shared;
using System.IO;
namespace Oqtane.Modules.Admin.Files.Manager
{
public class FileManager : ISearchable
{
private readonly IFolderRepository _folderRepository;
private readonly IFileRepository _fileRepository;
private const string DocumentExtensions = ".txt,.htm,.html";
public FileManager(IFolderRepository folderRepository, IFileRepository fileRepository)
{
_folderRepository = folderRepository;
_fileRepository = fileRepository;
}
public async Task<List<SearchContent>> GetSearchContentsAsync(PageModule pageModule, DateTime lastIndexedOn)
{
await Task.CompletedTask;
var searchContents = new List<SearchContent>();
var folders = _folderRepository.GetFolders(pageModule.Module.SiteId);
foreach ( var folder in folders)
{
bool changed = false;
bool removed = false;
if (folder.ModifiedOn >= lastIndexedOn)
{
changed = true;
removed = folder.IsDeleted.Value;
}
var files = _fileRepository.GetFiles(folder.FolderId);
foreach (var file in files)
{
if (file.ModifiedOn >= lastIndexedOn || changed)
{
var path = folder.Path + file.Name;
var body = "";
if (DocumentExtensions.Contains(Path.GetExtension(file.Name)))
{
// get the contents of the file
body = System.IO.File.ReadAllText(_fileRepository.GetFilePath(file));
}
var searchContent = new SearchContent
{
SiteId = folder.SiteId,
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);
}
}
}
return searchContents;
}
}
}

View File

@ -53,7 +53,7 @@ namespace Oqtane.Modules.HtmlText.Manager
{
await Task.CompletedTask;
var searchContentList = new List<SearchContent>();
var searchContents = new List<SearchContent>();
var htmltexts = _htmlText.GetHtmlTexts(pageModule.ModuleId);
if (htmltexts != null && htmltexts.Any())
@ -61,7 +61,7 @@ namespace Oqtane.Modules.HtmlText.Manager
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
if (htmltext.CreatedOn >= lastIndexedOn)
{
searchContentList.Add(new SearchContent
searchContents.Add(new SearchContent
{
Title = pageModule.Module.Title,
Description = string.Empty,
@ -72,7 +72,7 @@ namespace Oqtane.Modules.HtmlText.Manager
}
}
return searchContentList;
return searchContents;
}
public void ImportModule(Module module, string content, string version)